GetFormHandle(FormName) etc...

Moderator: Rathinagiri

Post Reply
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

GetFormHandle(FormName) etc...

Post by KDJ »

h_windows.prg wrote:

Code: Select all

*-----------------------------------------------------------------------------*
Function GetFormHandle (FormName)
*-----------------------------------------------------------------------------*
Local mVar , i

	mVar := '_' + FormName

	i:=&mVar
	if i == 0
		Return 0
	endif

Return ( _HMG_SYSDATA [ 67  ] [ &mVar ] )
If you pass to this function a not defined FormName, run-time error occurs.
You can to avoid run-time error by a little improving the function. For example:

Code: Select all

Function GetFormHandle (FormName)
  LOCAL mVar := '_' + FormName

  IF (Type(mVar) == "N") .and. (&mVar > 0)
    RETURN ( _HMG_SYSDATA [ 67  ] [ &mVar ] )
  ENDIF

RETURN 0
The same applies to similar functions:
GetWindowType(FormName)
GetFormName(FormName)
GetFormToolTipHandle(FormName)
GetMenuToolTipHandle(FormName)
GetFormIndex(FormName)
GetControlIndex(ControlName, ParentForm)
GetControlName(ControlName, ParentForm)
GetControlHandle(ControlName, ParentForm)
GetControlContainerHandle(ControlName, ParentForm)
GetControlParentHandle(ControlName, ParentForm)
GetControlId(ControlName, ParentForm)
GetControlType(ControlName, ParentForm)
GetControlValue(ControlName, ParentForm)
GetControlPageMap(ControlName, ParentForm)
_GetControlRow(ControlName, ParentForm)
_GetControlCol(ControlName, ParentForm)
_GetControlWidth(ControlName, ParentForm)
_GetControlHeight(ControlName, ParentForm)
_GetControlObject(ControlName, ParentForm)
_PlayPlayer(ControlName, ParentForm)
_StopPlayer(ControlName, ParentForm)
_ClosePlayer(ControlName, ParentForm)
_DestroyPlayer(ControlName, ParentForm)
_EjectPlayer(ControlName, ParentForm)
...
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: GetFormHandle(FormName) etc...

Post by serge_girard »

Thanks!

Serge
There's nothing you can do that can't be done...
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: GetFormHandle(FormName) etc...

Post by srvet_claudio »

These are internal functions, it is the responsibility of the programmer to check the validity of the parameters, otherwise they generate responses type black boxes that are very difficult to debug.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: GetFormHandle(FormName) etc...

Post by KDJ »

Claudio, thanks for the explanation.

So we should write in this way:

IF _IsWindowDefined(cForm)
nHandle := GetFormHandle(cForm)
ENDIF

or

IF IsWindowDefined(&cForm)
nHandle := GetFormHandle(cForm)
ENDIF
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: GetFormHandle(FormName) etc...

Post by srvet_claudio »

It right
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: GetFormHandle(FormName) etc...

Post by Rathinagiri »

srvet_claudio wrote: Sun Jan 29, 2017 5:07 pm These are internal functions, it is the responsibility of the programmer to check the validity of the parameters, otherwise they generate responses type black boxes that are very difficult to debug.
Perfect Claudio.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

GetFormHandle(FormName) etc...

Post by Pablo César »

+ Just my opinion +
I understand what colleague Krzysztof means and understand what Claudio says as well.

I think the two are right and that by default, the programmer uses _FunctionName() to denote that it is an internal function and that it is possibly subject to change. But at this point in our progress, making a change seems difficult to accept, probably also due main reason have to provide for backwards compatibility and this displays more code ...

We have to be aware in adding that many things have been created and improved over time. It is always necessary to decide whether such a change or any other change is worth the effort.

For my concept although the risk of using these "internal functions" is understandable. They are and are nothing more than one function to more in the system. Of course the "internal" type of function that requires care. Sometimes the procedure is not complete in direct use or/and are subject to change its functionality. For more one reason, the use of pseudo-function is great.

But to say (or think in it) that the user can not use (I do not say here is the case), I think it only requires precaution. Nothing else... :? :roll:
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: GetFormHandle(FormName) etc...

Post by srvet_claudio »

HMG was designed to be a high level language, so it is assumed that the use of advanced or low level functions are done by people who know in depth how Windows works and therefore it is the responsibility of the programmer to perform a defensive programming.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: GetFormHandle(FormName) etc...

Post by esgici »

Where is "like" button ?
Viva INTERNATIONAL HMG :D
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: GetFormHandle(FormName) etc...

Post by hmgchang »

Dear Friends,

How to tell the different :
1. GetControlContainerHandle(ControlName, ParentForm)
2. GetControlParentHandle(ControlName, ParentForm)
3. Will it be 1=2 ?

TIA

Best rgds
Chang
Just Hmg It !
Post Reply