Hi Mauricio.
1) about name. HMG3 compatibility require the ability to assign a name to the object. This ":Name" is been introduced with startup of HMG4 development and I think (at that moment) was the best solution. HMG3 handle in different way because it's different. The most important thing is to assign the name. When? IMHO when I create/define the object. How to? IMHO with a parameter in the New() method.
ie button
Code: Select all
OOP Style
WITH OBJECT button():New( cName )
....
END WITH
Code: Select all
XBASE style
#xcommand DEFINE BUTTON <ButtonName> => WITH OBJECT button():New( <"ButtonName"> )
n.b. Also, with previous syntax (WITH OBJECT) it's most relevant the order; the values assigned are "stable" only when reaching the END WITH
ie button
Code: Select all
WITH OBJECT button():New()
...
:Name := xxxx
END WITH
When New() method is execute, cName is empty. When END WITH is execute cName is xxxx.
I can apply this to HMG4, but it take a while. Tell me if I can start. This is an important rule: all team members agree?
2) about the existence of an object
first about __objDelData. In my experience, this harbour function remove the object but alters the structure of parent - objects.
Perhaps, with last harbour work fine or was a problem with my test program. Anyway, if you use it and work fine very good.
I'm sorry for my bad explanation. Th problem is to check if object it's already defined, but before to show solution a little brief of my experience
with Harbour object. When you use __objAddData you add a DATA (new object) to an object (parent); in HMG4 we use this function to have syntax: Parent:Object:....
But parent have a lot of prebuild Harbour DATA and name stored (if I understand very well) are case sensitive (this is the problem to use harbour _obj functions)
My solutions are two, but REMEMBER: this at oParent level.
A) When we use function AddData (that is, when we use __objAddData) we can add cName to an array (ie Childs)
Code: Select all
METHOD AddData( cObjName, oObject )
__objAddData( Self, cObjName )
::&cObjName := oObject
AADD( ::aChilds, ALLTRIM( LOWER( cObjName ) ) ) <=====
RETURN Self
If we want check if exist, we can use:
Code: Select all
METHOD NameIsDefined( cObjName )
LOCAL nX := ASCAN( ::aChilds, LOWER( ALLTRIM( cObjName ) ) )
RETURN IIF( nX>0, .T., .F. )
IF we want a list of controls we can use
Code: Select all
METHOD ControlList INLINE ::aChilds
IF we want to remove
Code: Select all
METHOD RemoveObject( oObject, cObjName )
LOCAL nX := ASCAN( ::aChilds, LOWER( ALLTRIM( cObjName ) ) )
IF nX > 0
::aChilds := hb_adel( ::aChilds, nX, .T. )
Self:__objDelData( oObject, cObjName )
ENDIF
RETURN Self
Problem in this last method: __objDelData requires oObject and cObjName. For me, everyone can be a problem. Bu if I use
Code: Select all
METHOD RemoveObject( cObjName )
LOCAL nX := ASCAN( ::aChilds, LOWER( ALLTRIM( cObjName ) ) )
IF nX > 0
::aChilds := hb_adel( ::aChilds, nX, .T. )
Self:&cObjName := NIL
ENDIF
RETURN Self
B) we can use aControls
Code: Select all
METHOD NameIsDefined( cObjName )
LOCAL nX, lReturn := .F.
FOR nX := 1 TO LEN( ::aControls )
lReturn := IIF( LOWER( ALLTRIM( cObjName ) ) == LOWER( ALLTRIM( ::aControls:Name() ) ), .T., .F. )
RETURN lReturn
but it is dangerous. An object can not be named?
3) about my last opinion
The problem is: why I RECREATE an object? I can alter properties or I want to remove, but IMHO I never create a BUTTON with name Button1 and then
I create a FORM with name Button1. This is my question.
Best regard