FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Startup function
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Startup function
Posted: Sun Oct 27, 2024 11:17 AM

Dear friends,

The MAIN() function is the startup function in Harbour and xHarbour. But in xHarbour the function MAIN() is the startup function only when its module is the first linked in. Do you know a way to specify a startup function in xHarbour that is not in the first linked module?

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Startup function
Posted: Mon Oct 28, 2024 11:52 AM
Dear Enrico,

See this in source/vm/hvm.c
/* if first char is '@' then start procedure were set by
* programmer explicitly and should have the highest priority
* in other case it's the name of first public function in
* first linked moudule which is used if there is no
* HARBOUR_START_PROCEDURE in code
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Mon Oct 28, 2024 12:04 PM

Dear Antonio,

Can you explain, please? I don't understand how to set a specific startup function in xHarbour, if it is possible.

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Startup function
Posted: Mon Oct 28, 2024 01:48 PM

Dear Enrico,

I am not sure about it, either. I am just showing you what I found. Look for HARBOUR_START_PROCEDURE

  • source/pp/ppcore.c

    • Added predefined macro HB_MAIN. The macro is undefined or holds the

    value of HARBOUR_START_PROCEDURE depending on the compiler.

    Use this code to make your Harbour startup procedure platform/compiler

    independent:

    #ifndef HB_MAIN

      #define __HB_MAIN__ AppMain /* Or whatever you wish to call it */
    

    #endif

    FUNCTION HB_MAIN()

2003-08-02 12:00 UTC+0200 Przemyslaw Czerpak <druzus@polbox.com>

  • xharbour/make_tgz.sh

  • xharbour/xharbour.spec

  • xharbour/source/vm/hvm.c

    • small modification in support for automatic detection of first

    function in linked modules for Linux

    if first char of s_pszLinkedMain is '@' then start procedure were

    set by programmer explicitly and should have the highest priority

    in other case it's then name of first public function in first

    linked moudule which is used if there is no HARBOUR_START_PROCEDURE

    in code

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Mon Oct 28, 2024 02:17 PM
It doesn't work or I don't know how to use it. :-(
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Startup function
Posted: Tue Oct 29, 2024 07:54 AM

Me neither as function @Name() is not supported by the compiler...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Startup function
Posted: Wed Oct 30, 2024 01:23 PM
Sometimes I used @<funcname>() like this:
Code (fw): Select all Collapse
    p  := ( @XBROWSE() )
   ? P
   HB_ExecFromArray(  p, { "STATES.DBF" } )
Code (fw): Select all Collapse
p := ( @XBROWSE() )
works exactly like
Code (fw): Select all Collapse
p := HB_FuncPtr( "XBROWSE" )
Regards



G. N. Rao.

Hyderabad, India
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Wed Oct 30, 2024 01:31 PM

Yes, it is the "address of" operator. But it has nothing to do with my request.

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Startup function
Posted: Wed Oct 30, 2024 02:40 PM
Good morning Enrico. I don't quite understand what you want, wouldn't it be this:

https://www.hamor.ro/distr_ext/Doc/xHb/xHarbour%20Language%20Reference/Statements/Init_procedure.en.html

??

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Wed Oct 30, 2024 03:04 PM

No. Look: Harbour uses MAIN() as the startup function even if it is not in the main PRG. xHarbour uses MAIN() only if it is in the main PRG. If it is not, xHarbour calls the first function defined in the main PRG. How to force xHarbour to call MAIN() even if it is not in the main PRG?

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Startup function
Posted: Wed Oct 30, 2024 03:16 PM

I'm sorry. I've never seen anything like this. Why do you need this? What is the purpose?

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Wed Oct 30, 2024 03:49 PM

I just want that MAIN() is always executed at startup even if it is not in the main PRG, just like Harbour already does.

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Startup function
Posted: Wed Oct 30, 2024 04:32 PM

Enrico, I learned it like this:

How to create an EXEcutable:

It is mandatory to have a FUNCTION MAIN() within your system, you already know this, but in xHarbour, even if you are compiling a single PRG, you will need to start with FUNCTION MAIN() too!

Enrico, lo aprendí así:

Cómo crear un ejecutable:

Es obligatorio tener una FUNCTION MAIN() dentro de su sistema, ya lo sabe, pero en xHarbour, incluso si está compilando un solo PRG, ¡también necesitará comenzar con FUNCTION MAIN()!

I've never seen any other way.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Startup function
Posted: Wed Oct 30, 2024 05:18 PM

No, it is not mandatory to have a FUNCTION MAIN()! If you do not define it, the first function defined in the first linked PRG is executed at startup. But if you define it then the Harbour and xHarbour behaviour is different: Harbour executes it even if it is not in the first linked PRG while xHarbour execute it only if it is defined in the first linked PRG, otherwise it executes the first function defined in the first linked PRG, ignoring the MAIN() defined in another PRG. I don't know how to explain it better, sorry.

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Startup function
Posted: Wed Oct 30, 2024 05:31 PM
If I understand you correctly... Is that +-?
Code (fw): Select all Collapse
// C:\FWH\SAMPLES FUNCMAIN.PRG

#include "FiveWin.ch"

STATIC oWnd

FUNCTION Principal() // INIT PROCEDURE Principal // Main

  ? "I am the Principal() function"

  Main()

RETURN NIL

FUNCTION Main()

  ? "I am the Main() function"

RETURN NIL

// FIN / END
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341