how to do routin after main form display?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

how to do routin after main form display?

Post by huangchenmin »

Dear all:
I would like to do procedure/function once main form showed. both of inner/outer definition of window/end window fail.
Could anyone provide suggestion.
Best Regards
chen min
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: how to do routin after main form display?

Post by esgici »

huangchenmin wrote: ...
Could anyone provide suggestion?
Probably, if you could explain your demand by a little example ;)

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: how to do routin after main form display?

Post by huangchenmin »

Probably, if you could explain your demand by a little example ;)
Regards
--
Esgici[/quote]

Dear Sir
Attachments are screen shot and .prg file,
Wat I want to do is simple, main form show once .exe was executed.
function R_PI() was executed after main form showed.
For doing that, I call R_PI() within definition of form rather out of.

I had tried before call function before center and activate window.
But the function seem didn't been executed.
PLS HELP
Attachments
ReadIC.rar
(2.16 MiB) Downloaded 308 times
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: how to do routin after main form display?

Post by nguyenchiduc »

In my case.

When I start program, I test some files exist in Intranet (NOVELL). Example:

G:\GDICH1\HT_HS\DBFS\thao.dbf and P:\HD\dm2.dbf in NOVELL shared in intranet not in my PC.

Code: Select all

FUNCTION MAIN

        /* Commands */

   IF FILE("G:\GDICH1\HT_HS\DBFS\thao.dbf") == .F.
       MSGBOX("Phai dang nhap NOVELL moi chay chuong trinh","THONG BAO")
       quit
   ELSE        
       set default to  G:\GDICH1\HT_HS\DBFS
       USE thao index thao alias thao SHARED NEW READONLY via "DBFCDX"
       set order to 3 in thao
       set default to c:\khongma\data                     
  ENDIF
   
   IF FILE("P:\HD\dm2.dbf") == .F. .OR. FILE("P:\HD\dm2.dbf") == .F.
       MSGBOX("Thu muc P:\HD chua vao","THONG BAO")
       quit
   ELSE
       set default to  P:\HD
       USE dm2 index dm2 alias dm2 SHARED NEW READONLY via "DBFCDX"
       set order to 2 in dm2
    
       USE dm1 index dm1 alias dm1 SHARED NEW READONLY via "DBFCDX"
       set order to 1 in dm1
       set default to c:\khongma\data                              
   ENDIF
...
...
...
...DEFINE WINDOW Form_Main
...      /* LABEL, BUTTON, GRID, BROWSE, TEXTBOX... */
...
...END WINDOW

   CENTER WINDOW Form_Main
   ACTIVATE WINDOW Form_Main

RETURN

FUNCTION program1()
   /* commands */
RETURN NIL

FUNCTION program2()
   /* commands */
RETURN NIL

FUNCTION program3()
   /* commands */
RETURN NIL

FUNCTION program4()
   /* commands */
RETURN NIL
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: how to do routin after main form display?

Post by nguyenchiduc »

Do you use ON INIT com_init() or R_PI() on WINDOW CardInfo ?

Code: Select all

DEFINE WINDOW CardInfo
  /* commands */
END WINDOW
...
...
function com_init()
   /* commands */
return m_comport
function R_PI()
   /* commands */
return
Image
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: how to do routin after main form display?

Post by esgici »

huangchenmin wrote: Attachments are screen shot and .prg file,
Dear Huang

I can't run your .prg :(

If I understood right, your problem is:
huangchenmin wrote:I had tried call function before center and activate window.
Sadly, this is impossible. Because for using any GUI control, the form that include that GUI control must exist (defined and activated).

Only exception are MsgXxxx() functions. These are predefined individual controls independent from user defined forms. In fact they aren't simply control, but each is separate window (form) built by system.

Most early time that you call any job (routine) is ON INIT event. This event fired after your form activated and before begin event loop of your form.

You can find more info here.

I hope that this will help you.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: how to do routin after main form display?

Post by dhaine_adp »

Dear all:
I would like to do procedure/function once main form showed. both of inner/outer definition of window/end window fail.
Could anyone provide suggestion.
Best Regards
chen min
Hi Chen,

If I am not mistaken, your problem is about the control of UI (User Interface). Basically you should plan ahead of the interface. Add more controls as you needed and don't confine on init procedure only. Please explore the samples of HMG that comes along with the distribution. From there you would see the basic implementation and as you go along and become familiar with each control's behaviour. You would learn the tricks. What you need right now is more patience and determination.

With regards to your posted code (.rar file), it seems that you are attempting to send something over the Comm Port. Anyway on init procedure can be use in a variety of ways such as:

(1) Open a set of tables or database
(2) Generate splash screens
(3) Or do nothing at all simply display the main window and many more....

In the .prg file from the .rar file, I think instead of using on Init to open the comm port, it would be much better to add some buttons to handle the procedure that you want to run. By using various controls such as Buttons, Checkboxes with on change event you can fire up your procedures easily.

Another example is that when you use button control with caption "Send" that's the time you open the comm port and if it is sucessful, that's the time you can begin to transmit.

I hope that you get the principles.

Another thing is from your posting:

If you use files from the network, at least make a permanent drive mapping on the workstation. Then put the database filename in a private or public variables. Example:

dbThao := "G:\GDICH1\HT_HS\DBFS\thao"
dbDm2 := "P:\HD\dm2"

IF FILE( "&dbThao" + ".dbf" )
* do your code here *
endif
IF FILE( "&dbDm2" + ".dbf" )
* same here
endif

USE ( dbThao ) INDEX ( dbThao ) ALIAS THAO SHARED NEW READONLY via "DBFCDX"

Like that would be much easier to maintain and to edit... Well anyway it just a suggestion and there are many ways to achieved the same. In the end its your call my friend....

Regards,

Danny
Regards,

Danny
Manila, Philippines
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: how to do routin after main form display?

Post by huangchenmin »

nguyenchiduc wrote:Do you use ON INIT com_init() or R_PI() on WINDOW CardInfo ?

Code: Select all

DEFINE WINDOW CardInfo
  /* commands */
END WINDOW
...
...
function com_init()
   /* commands */
return m_comport
function R_PI()
   /* commands */
return
Image
Thanks for supprots!
This reall solve my question!
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: how to do routin after main form display?

Post by huangchenmin »

huangchenmin wrote:Dear all:
I would like to do procedure/fun............
chen min
Thanks for guys support me.
I learn much more than just solution.
To me, there are long way to go.
Someday, I hope that I can make contribution to people here.
Best Regards
chen min
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: how to do routin after main form display?

Post by esgici »

huangchenmin wrote:To me, there are long way to go.
Hi Chen

This is correct for everyone; nobody have 'short' way to go ;)

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
Post Reply