Page 1 of 1

hmg4 Name and Parent methods

Posted: Sat Sep 03, 2011 7:20 pm
by l3whmg
Hi friends
I found many program they use syntax ":Name :=" and ":Parent :=" to assign the name and the parent.
Some time ago, Mauricio and me have introduced a change for which the name and the parent must be defined when using the New method.
On the other hand, I think the Parent method is dangerous, because it does not take care about Qt parent. This is the current code:

Code: Select all

METHOD Parent( oValue ) CLASS CONTROL

   IF PCOUNT() == 0
      RETURN ::oParent
   ENDIF

   // If the parent is already the one, do nothing
   IF VALTYPE(::oParent) == "U" .OR. oValue:cName != ::oParent:Name

      // Remove from the old parent stack
      IF VALTYPE(::oParent) != "U"
         ::oParent:ChildRemove( ::cName )
      ENDIF

      ::oParent := oValue

      // Add to the new parent stack
      ::oParent:ChildAdd( ::cName, Self )

   ENDIF

   RETURN NIL
For this reason, I want proceed to do these changes

Code: Select all

METHOD Name() CLASS BASIC

   RETURN ::cName
and this one

Code: Select all

METHOD Parent() CLASS CONTROL
   RETURN ::oParent
I did some tests, for example with demo within "samples\layout", and I have no faults detected.

Could you please tell me if can I proceed?

Cheers

Re: hmg4 Name and Parent methods

Posted: Sat Sep 03, 2011 10:04 pm
by mrduck
l3whmg wrote: On the other hand, I think the Parent method is dangerous, because it does not take care about Qt parent.
Exactly !

reparenting to the correct Qt object is necessary !

In this way Qt knows that the object has a parent and correctly handles their deletion....

Re: hmg4 Name and Parent methods

Posted: Sun Sep 04, 2011 8:39 am
by l3whmg
Hi friends, please see this Changelog viewtopic.php?f=32&t=1777&start=30

Cheers