Page 1 of 1

GetFormHandle(FormName) etc...

Posted: Sun Jan 29, 2017 4:55 pm
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)
...

Re: GetFormHandle(FormName) etc...

Posted: Sun Jan 29, 2017 4:58 pm
by serge_girard
Thanks!

Serge

Re: GetFormHandle(FormName) etc...

Posted: Sun Jan 29, 2017 5:07 pm
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.

Re: GetFormHandle(FormName) etc...

Posted: Sun Jan 29, 2017 6:30 pm
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

Re: GetFormHandle(FormName) etc...

Posted: Sun Jan 29, 2017 10:01 pm
by srvet_claudio
It right

Re: GetFormHandle(FormName) etc...

Posted: Mon Jan 30, 2017 4:07 am
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.

GetFormHandle(FormName) etc...

Posted: Mon Jan 30, 2017 10:51 am
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:

Re: GetFormHandle(FormName) etc...

Posted: Mon Jan 30, 2017 4:30 pm
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.

Re: GetFormHandle(FormName) etc...

Posted: Mon Jan 30, 2017 4:58 pm
by esgici
Where is "like" button ?

Re: GetFormHandle(FormName) etc...

Posted: Tue May 29, 2018 12:49 pm
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