How to reference an Object from one prg to another

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
CCH4CLIPPER
Posts: 140
Joined: Tue Mar 03, 2009 8:59 am

How to reference an Object from one prg to another

Post by CCH4CLIPPER »

Hi

In Main.prg
========
1) DEFINE WINDOW MainForm ;
AT 0,0 ;
WIDTH 450 ;
HEIGHT 150 ;
MAIN;
@ (MainForm.height/2)-18,(MainForm.width/2)-200 PROGRESSBAR Progress_1 RANGE 0,100 WIDTH 400 HEIGHT 30
@ (MainForm.height/2)-48-18,(MainForm.width/2)-200 LABEL Label_001 VALUE "Completed :" WIDTH 400 HEIGHT18
END WINDOW
CENTER WINDOW MainForm

ACTIVATE WINDOW MainForm

2) In Another.prg
=============
nComplete := INT((nCounter/nTotalRec) * 100)
cComplete := LTRIM(STR(nComplete))

MainForm.Progress_1.Value := nComplete
MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

Q. How do I reference MainForm.Progress_1.Value in Another.prg to the one created in Main.prg ?

CCH
http://cch4clipper.blogspot.com
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: How to reference an Object from one prg to another

Post by PeteWG »

CCH4CLIPPER wrote:Hi

In Main.prg
========
1) DEFINE WINDOW MainForm ;
AT 0,0 ;
WIDTH 450 ;
HEIGHT 150 ;
MAIN;
@ (MainForm.height/2)-18,(MainForm.width/2)-200 PROGRESSBAR Progress_1 RANGE 0,100 WIDTH 400 HEIGHT 30
@ (MainForm.height/2)-48-18,(MainForm.width/2)-200 LABEL Label_001 VALUE "Completed :" WIDTH 400 HEIGHT18
END WINDOW
CENTER WINDOW MainForm

ACTIVATE WINDOW MainForm

2) In Another.prg
=============
nComplete := INT((nCounter/nTotalRec) * 100)
cComplete := LTRIM(STR(nComplete))

MainForm.Progress_1.Value := nComplete
MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

Q. How do I reference MainForm.Progress_1.Value in Another.prg to the one created in Main.prg ?

CCH
http://cch4clipper.blogspot.com
Perhaps you could try to put on top of your Another.prg the line

DECLARE WINDOW MainForm

and see if it helps..

---
Pete
CCH4CLIPPER
Posts: 140
Joined: Tue Mar 03, 2009 8:59 am

Re: How to reference an Object from one prg to another

Post by CCH4CLIPPER »

Hi Pete

TQVM for your speedy response

Just added DECLARE WINDOW MainForm to the top of my pay_mth.prg and still have syntax error

Compiling 'PAY_MTH.PRG'...
PAY_MTH.PRG(692) Error E0030 Syntax error "syntax error at '.'"
PAY_MTH.PRG(693) Error E0030 Syntax error "syntax error at '.'"
2 errors

Line 692 MainForm.Progress_1.Value := nComplete
Line 692 MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

Any other suggestions ?
PeteWG
Posts: 176
Joined: Sun Mar 21, 2010 5:45 pm

Re: How to reference an Object from one prg to another

Post by PeteWG »

CCH4CLIPPER wrote:Hi Pete

TQVM for your speedy response

Just added DECLARE WINDOW MainForm to the top of my pay_mth.prg and still have syntax error

Compiling 'PAY_MTH.PRG'...
PAY_MTH.PRG(692) Error E0030 Syntax error "syntax error at '.'"
PAY_MTH.PRG(693) Error E0030 Syntax error "syntax error at '.'"
2 errors

Line 692 MainForm.Progress_1.Value := nComplete
Line 692 MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

Any other suggestions ?
CCH4CLIPPER wrote:Hi Pete

TQVM for your speedy response

Just added DECLARE WINDOW MainForm to the top of my pay_mth.prg and still have syntax error

Compiling 'PAY_MTH.PRG'...
PAY_MTH.PRG(692) Error E0030 Syntax error "syntax error at '.'"
PAY_MTH.PRG(693) Error E0030 Syntax error "syntax error at '.'"
2 errors

Line 692 MainForm.Progress_1.Value := nComplete
Line 692 MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

Any other suggestions ?
It is possible that the culprit is lying in another line of your code.
(for example: the line
@ (MainForm.height/2)-48-18,(MainForm.width/2)-200 LABEL Label_001 VALUE "Completed :" WIDTH 400 HEIGHT18
has a typo at HEIGHT18 (there is a missing space between 'HEIGHT' and '18')

By the way, could you post your starting lines of your PAY_MTH.PRG ?


---
Pete
CCH4CLIPPER
Posts: 140
Joined: Tue Mar 03, 2009 8:59 am

Re: How to reference an Object from one prg to another

Post by CCH4CLIPPER »

Hi Pete

1) Pay_mth.prg
DECLARE WINDOW MainForm

2) Just checked my codes, there is a space :-)

BTW, just chatted with Sudip and he suggested using SETPROPERTY().

// MainForm.Progress_1.Value := nComplete
SETPROPERTY(MainForm,Progress_1,Value,nComplete)

//MainForm.Label_001.Value := "Processing "+ str(nCounter)+'/'+ltrim(str(nTOtalRec))+CHR(13)+ "Percentage completed "+cComplete + "%"

SETPROPERTY(MainForm,Label_001,Value,"Processing "+ str(nRunNo)+'/'+ltrim(str(nTOtNo))+CHR(13)+ "Percentage completed "+cComplete + "%")

It seems to work as there are no more compile errors reported by hbmk2 :-)

Cheers
CCH
http://cch4clipper.blogspot.com
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to reference an Object from one prg to another

Post by Rathinagiri »

In HMG4, the management of controls are entirely different. Previously a BIG public array is used to store all the windows/controls attributes (like name, handle, width, height, row, col etc).

HMG4 should also have such an array at least to hold the window/control object names. Until such time, you have to define the names of the controls/windows as public variables. Thereby you can refer an object from one prg to another.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
CCH4CLIPPER
Posts: 140
Joined: Tue Mar 03, 2009 8:59 am

Re: How to reference an Object from one prg to another

Post by CCH4CLIPPER »

Hi Rathinagiri

Thanks for your tip :-)

CCH
http://cch4clipper.blogspot.com
CCH4CLIPPER
Posts: 140
Joined: Tue Mar 03, 2009 8:59 am

Re: How to reference an Object from one prg to another

Post by CCH4CLIPPER »

Hi Rathinagiri
rathinagiri wrote:In HMG4, the management of controls are entirely different. Previously a BIG public array is used to store all the windows/controls attributes (like name, handle, width, height, row, col etc).

HMG4 should also have such an array at least to hold the window/control object names. Until such time, you have to define the names of the controls/windows as public variables. Thereby you can refer an object from one prg to another.
I tried declaring PUBLIC MainForm in the main.prg but referencing say in another.prg

MainForm.Progress_1.Value := nComplete

resulted in a Error E0030 Syntax error "syntax error at '.'"

This was despite DECLARE WINDOW MainForm (at top of another.prg) and explicitly declared MEMVAR Mainform

Please revert, TIA

CCH
http://cch4clipper.blogspot.com
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to reference an Object from one prg to another

Post by Rathinagiri »

Thanks for reporting. I will check that out.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply