Startup function

Startup function

Postby Enrico Maria Giordano » 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?
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Startup function

Postby Enrico Maria Giordano » 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.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby Antonio Linares » Mon Oct 28, 2024 1: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Startup function

Postby Enrico Maria Giordano » Mon Oct 28, 2024 2:17 pm

It doesn't work or I don't know how to use it. :-(
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby Antonio Linares » Tue Oct 29, 2024 7:54 am

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Startup function

Postby nageswaragunupudi » Wed Oct 30, 2024 1:23 pm

Sometimes I used @<funcname>() like this:

Code: Select all  Expand view  RUN
   p  := ( @XBROWSE() )
   ? P
   HB_ExecFromArray(  p, { "STATES.DBF" } )


Code: Select all  Expand view  RUN
p := ( @XBROWSE() )

works exactly like
Code: Select all  Expand view  RUN
p := HB_FuncPtr( "XBROWSE" )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Startup function

Postby Enrico Maria Giordano » Wed Oct 30, 2024 1:31 pm

Yes, it is the "address of" operator. But it has nothing to do with my request.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby karinha » Wed Oct 30, 2024 2: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
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Startup function

Postby Enrico Maria Giordano » Wed Oct 30, 2024 3: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?
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby karinha » Wed Oct 30, 2024 3: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
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Startup function

Postby Enrico Maria Giordano » Wed Oct 30, 2024 3: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.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby karinha » Wed Oct 30, 2024 4: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
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Startup function

Postby Enrico Maria Giordano » Wed Oct 30, 2024 5: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.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Startup function

Postby karinha » Wed Oct 30, 2024 5:31 pm

If I understand you correctly... Is that +-?

Code: Select all  Expand view  RUN

// 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
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests