GetFormHandle(FormName) etc...

Moderator: Rathinagiri

Post Reply
KDJ
Posts: 201
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 226 times

GetFormHandle(FormName) etc...

Post by KDJ » Sun Jan 29, 2017 4:55 pm

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: 2045
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 404 times
Been thanked: 89 times
Contact:

Post by serge_girard » Sun Jan 29, 2017 4:58 pm

Thanks!

Serge

User avatar
srvet_claudio
Posts: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » 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.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

KDJ
Posts: 201
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 226 times

Post by KDJ » Sun Jan 29, 2017 6:30 pm

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: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » Sun Jan 29, 2017 10:01 pm

It right
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Rathinagiri
Posts: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

Post by Rathinagiri » Mon Jan 30, 2017 4:07 am

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
Has thanked: 100 times
Been thanked: 179 times

Post by Pablo César » Mon Jan 30, 2017 10:51 am

+ 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: 2016
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 34 times
Been thanked: 143 times
Contact:

Post by srvet_claudio » Mon Jan 30, 2017 4:30 pm

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: 4439
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 323 times
Been thanked: 99 times
Contact:

Post by esgici » Mon Jan 30, 2017 4:58 pm

Where is "like" button ?
Viva INTERNATIONAL HMG :D

User avatar
hmgchang
Posts: 238
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Tue May 29, 2018 12:49 pm

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