How do i call a procedure

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

How do i call a procedure

Post by ROBROS »

Hi to all,

my first small programs run in hmg with very few modifications. I created a main procedure with main window as shown in the samples, I can call procedures from procedure main. When all procedures are done, main window shows up and I have do terminate the program by clickin on "x" in the upper right corner.

Is there a way to call procedures from a popup like shown below, and what are the appropriate commands?

#include "hmg.ch"

Function Main

DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE 'Tutor 02 - Property Test' ;
MAIN

DEFINE MAIN MENU
POPUP "First Popup"
ITEM 'Change Window Title' ACTION Win_1.Title := 'New Title' &&on select this do proc1
ITEM 'Retrieve Window Title' ACTION MsgInfo ( Win_1.Title ) &&on select this do proc2
END POPUP
END MENU

END WINDOW

ACTIVATE WINDOW Win_1

Return

I couldn't find a suiting sample so far and hope you can help.

Thank you
Robert
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: How do i call a procedure

Post by bpd2000 »

Add following code:

ITEM "E&xit" ACTION Win_1.Release
BPD
Convert Dream into Reality through HMG
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How do i call a procedure

Post by edk »

You can "do procedure" in the same way as call function.

Code: Select all

ITEM 'Change Window Title' ACTION proc1() &&on select this do proc1
ITEM 'Retrieve Window Title' ACTION proc2() &&on select this do proc2
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: How do i call a procedure

Post by ROBROS »

@ BPD Thank you: ITEM "&EXIT" ... is very useful I tried "deactivate"

@ edk: I tried do procedure.

Many thanks
Robert
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: How do i call a procedure

Post by ROBROS »

Here I am back again.
@ edk: your suggestion doesn't work. Are there any settings to be done to make it work?

But another question: maybe 2 weeks ago I stumbled across a fully featured demo-program with checkbox, datepicker, calendar function and on and on, but I can't find the site again. Anybody an idea?

Regards
Robert
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How do i call a procedure

Post by edk »

ROBROS wrote: Wed Jul 19, 2017 6:50 pm @ edk: your suggestion doesn't work. Are there any settings to be done to make it work?
Strange, this code work like a charm:

Code: Select all

#include "hmg.ch"

Function Main

DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE 'Tutor 02 - Property Test' ;
MAIN

DEFINE MAIN MENU
POPUP "First Popup"
ITEM 'DO proc1' ACTION proc1() &&on select this do proc1
ITEM 'DO proc2' ACTION proc2() &&on select this do proc2
ITEM "E&xit" ACTION ThisWindow.Release
END POPUP
END MENU

END WINDOW

ACTIVATE WINDOW Win_1

Return
*********************************
PROCEDURE proc1
Local i

FOR i=1 TO 100
   i:=i*i
Next i
MsgInfo('Result: '+hb_ValToStr(i), 'proc1')
RETURN 

*********************************
PROCEDURE proc2
Local i

FOR i=1 TO 100
    i:=i+i 
Next i
MsgInfo('Result: '+hb_ValToStr(i), 'proc2')
RETURN
Unless I misunderstood your question. My English is not very good. :(
But another question: maybe 2 weeks ago I stumbled across a fully featured demo-program with checkbox, datepicker, calendar function and on and on, but I can't find the site again.
There may be helpful samples from the HMG installation:
c:\hmg.3.4.4\SAMPLES\Basics\MAIN_DEMO\
c:\hmg.3.4.4\SAMPLES\Controls\MonthCalendar\
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: How do i call a procedure

Post by ROBROS »

Thank you very much, MAIN_DEMO is, what I was looking for, I searched the web for it, and it is part of HMG-distribution, by Roberto Lopez.

Regards
Robert
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: How do i call a procedure

Post by ROBROS »

@ edk: Sorry, absolutely my fault.
Up to now I used xbase++ in text mode, compiled the single prg-files and called them sequently via command line *.bat.

Robert
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How do i call a procedure

Post by edk »

You can also add all .prg files references into .hbp project file and compile to one exe. All functions and procedures will be included.
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: How do i call a procedure

Post by ROBROS »

FEEDBACK:

I did how you told me, works just fine.

Thank you
Robert
Post Reply