Objects added two times: problem o misunderstanding?
Posted: Wed Jun 08, 2011 9:28 pm
Hi friends.
I'm trying to find solution for some problems and for this reason I create a little fork of HMG4 with copy and paste.
I think I've found a problem or perhaps I can't understand the source code. Can you help me?
Problem: when we add the current object to its parent (to use syntax FormName:Control), I think we add two times the same object with different names.
Example: button.
Code from button.prg
Code from control.prg
====>0 Here, we assign the name _HMG_OBJECT_xxxxxxx
====>1 Here, we add the object named _HMG_OBJECT_xxxxxxx to its parent (ie now we can use FormName:_HMG_OBJECT_xxxxxxx)
Code from basic.prg
====>2 Here, we assign AND CHANGE the name. We add the object named "button1" to its parent (ie now we can use FormName:button1)
source code WITHOUT use of :Name method
we have added only ONE time an object (named _HMG_OBJECT_xxxxxxx) to its parent
source code WITH use of :Name method
we have added, the same object, TWO times: one time named _HMG_OBJECT_xxxxxxx and another time named button1
My analysis is correct or is a misunderstanding? If it's correct, IMHO we have the risk of unnecessarily fill the memory.
Best regards and many thanks in advance for any help.
I'm trying to find solution for some problems and for this reason I create a little fork of HMG4 with copy and paste.
I think I've found a problem or perhaps I can't understand the source code. Can you help me?
Problem: when we add the current object to its parent (to use syntax FormName:Control), I think we add two times the same object with different names.
Example: button.
Code from button.prg
Code: Select all
METHOD New( oParent ) CLASS BUTTON
Super:New( oParent ) ====>0
::oQTObject := QPushButton( ::oParent:oQTObject )
::oFont := ::oQTObject:Font()
::oParent:AddData( ::cName , Self ) ====>1
Code: Select all
METHOD New( oParent ) CLASS CONTROL
IF !::lGridCellFlag
::nObjectCounter++
::cName := '_HMG_OBJECT_' + AllTrim( Str( Int( ::nObjectCounter ) ) ) ====>0
====>1 Here, we add the object named _HMG_OBJECT_xxxxxxx to its parent (ie now we can use FormName:_HMG_OBJECT_xxxxxxx)
Code from basic.prg
Code: Select all
METHOD Name( cValue ) CLASS BASIC
IF Pcount() == 0
RETURN ::cName
ELSEIF Pcount() == 1
IF ::cName != cValue
::cName := cValue
::oParent:AddData( ::cName, Self ) ====> 2
source code WITHOUT use of :Name method
Code: Select all
WITH OBJECT oWin := Window():New()
WITH OBJECT Button():New()
END WITH
END WITH
source code WITH use of :Name method
Code: Select all
WITH OBJECT oWin := Window():New()
WITH OBJECT Button():New()
:Name := "Button1"
END WITH
END WITH
My analysis is correct or is a misunderstanding? If it's correct, IMHO we have the risk of unnecessarily fill the memory.
Best regards and many thanks in advance for any help.