hmg4 Name and Parent methods

Moderator: Rathinagiri

Post Reply
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

hmg4 Name and Parent methods

Post 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
Luigi from Italy
www.L3W.it
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: hmg4 Name and Parent methods

Post 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....
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: hmg4 Name and Parent methods

Post by l3whmg »

Hi friends, please see this Changelog viewtopic.php?f=32&t=1777&start=30

Cheers
Luigi from Italy
www.L3W.it
Post Reply