Página 1 de 1

Destroying controls?

Publicado: Jue Jul 28, 2011 4:19 pm
por ChrisGillard
I have a program that is making some edit & button controls in code, all
with a TGroupBox parent. This works fine.
oLabel := TLabel():New( ::oEditGroupBox )
oLabel:SetBounds( 50, 50, 100, 25 )
oLabel:cText := aRow[SE_EDITTEXT]
oLabel:Create()
oEdit := TMaskEdit():New( ::oEditGroupBox )
oEdit:SetBounds( 50, 100, 100, 25 )
oEdit:Create()
oSaveBtn := TButton():New( ::oEditGroupBox )
oSaveBtn:SetBounds( 50, 150, 100, 25 )
oSaveBtn:cText := "&Save"
oSaveBtn:Create()
oSaveBtn:OnClick := { |oSender| ::oIni:SetEntry( aRow[SE_SECTION],
aRow[SE_ENTRY], oEdit:value ) }
I want to clear/destroy these before I make a different combination of edit
& button controls.
So to destroy the controls on my TGroupBox I do something like this ....
Method ClearEditGroupBox() Class TForm1
local elem
FOR EACH elem IN ::oEditGroupBox:aControls
elem:destroy()
NEXT
::oEditGroupBox:Redraw()
RETURN Nil
This does not remove all controls, but leaves some visible which stay there
when I make some new controls in the TGroupBox.
So question is how to TOTALLY remove some TEdit & TButton controls made in
code, before I make some new ones in the TGroupbox..
I hope I have made this understandable!!
Chris

Destroying controls?

Publicado: Jue Jul 28, 2011 4:48 pm
por ignacio
Chris Gillard escribió el jue, 28 julio 2011 16:19So question is how to TOTALLY remove some TEdit & TButton controls
Chris,
Try this (have not tested):
with object ::oEditGroupBox
do while Len( :aControls ) > 0
:RemoveControl( :aControls[ 1 ] )
end do
end with

Regards,

Destroying controls?

Publicado: Jue Jul 28, 2011 5:47 pm
por ChrisGillard
Ignacio,
Thanks for that code.
The loop is reducing the len to aControls to ZERO as it should ... good.
But the Groupbox still has the 'image' of the controls visible.
I have tried GroupBox:Redraw() & GroupBox:Refresh()
Still the 'image' stays.
When new controls are created, I see the new ones and the old ones.
Any thoughts
Chris
"Ignacio Ortiz de Zúñiga" <nonametoavoidspam@xailer.com> wrote in
message news:4e3176c0$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Chris Gillard escribió el jue, 28 julio 2011 16:19
>> So question is how to TOTALLY remove some TEdit &
>> TButton controls
>
>
> Chris,
> Try this (have not tested):
> with object ::oEditGroupBox
> do while Len( :aControls ) > 0
> :RemoveControl( :aControls[ 1 ] )
> end do
> end with
>
>
> Regards,
> --
> Ignacio Ortiz de Zúñiga
> [Equipo de Xailer/Xailer team]
> http://www.xailer.com
> http://www.xailer.info

Destroying controls?

Publicado: Jue Jul 28, 2011 8:30 pm
por ignacio
Chris Gillard escribió el jue, 28 julio 2011 17:47Ignacio,
Thanks for that code.
The loop is reducing the len to aControls to ZERO as it should ... good.
But the Groupbox still has the 'image' of the controls visible.
I have tried GroupBox:Redraw() & GroupBox:Refresh()
Still the 'image' stays.
When new controls are created, I see the new ones and the old ones.
Any thoughts

Try this (have not tested):
with object ::oEditGroupBox
do while Len( :aControls ) > 0
:aControls[ 1 ]:End()
end do
end with

Destroying controls?

Publicado: Jue Jul 28, 2011 10:02 pm
por ChrisGillard
Hi Ignacio,
Thanks very much for persevering.
Your code errored with array access on the :RemoveControl( :aControls[
1 ] ) line.
I changed to this and it appears to work. The second loop is probably not
doing anything.
with object ::oEditGroupBox
do while Len( :aControls ) > 0
:aControls[ 1 ]:End()
end do
do while Len( :aControls ) > 0
:RemoveControl( :aControls[ 1 ] )
end do
:Redraw()
:Refresh()
end with
Seems to do what I want.
If you think thats OK I will go with this?
Chris
"Ignacio Ortiz de Zúñiga" <nonametoavoidspam@xailer.com> wrote in
message news:4e31aadb$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Chris Gillard escribió el jue, 28 julio 2011 17:47
>> Ignacio,
>>
>> Thanks for that code.
>>
>> The loop is reducing the len to aControls to ZERO as it
>> should ... good.
>>
>> But the Groupbox still has the 'image' of the controls
>> visible.
>>
>> I have tried GroupBox:Redraw() & GroupBox:Refresh()
>>
>> Still the 'image' stays.
>>
>> When new controls are created, I see the new ones and
>> the old ones.
>>
>> Any thoughts
>
>
> Try this (have not tested):
>
> with object ::oEditGroupBox
> do while Len( :aControls ) > 0
> :aControls[ 1 ]:End()
> :RemoveControl( :aControls[ 1 ] )
> end do
> end with
>
> --
> Ignacio Ortiz de Zúñiga
> [Equipo de Xailer/Xailer team]
> http://www.xailer.com
> http://www.xailer.info

Destroying controls?

Publicado: Vie Jul 29, 2011 9:28 am
por ignacio
Chris Gillard escribió el jue, 28 julio 2011 22:02Hi Ignacio,
Thanks very much for persevering.
Your code errored with array access on the :RemoveControl( :aControls[
1 ] ) line.
I changed to this and it appears to work. The second loop is probably not
doing anything.
with object ::oEditGroupBox
do while Len( :aControls ) > 0
:aControls[ 1 ]:End()
end do
do while Len( :aControls ) > 0
:RemoveControl( :aControls[ 1 ] )
end do
:Redraw()
:Refresh()
end with
Seems to do what I want.
If you think thats OK I will go with this?
Chris
"Ignacio Ortiz de Zúñiga" <nonametoavoidspam@xailer.com> wrote in
message news:4e31aadb$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email][/email]
> Chris Gillard escribi� el jue, 28 julio 2011 17:47
>> Ignacio,
>>
>> Thanks for that code.
>>
>> The loop is reducing the len to aControls to ZERO as it
>> should ... good.
>>
>> But the Groupbox still has the 'image' of the controls
>> visible.
>>
>> I have tried GroupBox:Redraw() & GroupBox:Refresh()
>>
>> Still the 'image' stays.
>>
>> When new controls are created, I see the new ones and
>> the old ones.
>>
>> Any thoughts
>
>
> Try this (have not tested):
>
> with object ::oEditGroupBox
> do while Len( :aControls ) > 0
> :aControls[ 1 ]:End()
> :RemoveControl( :aControls[ 1 ] )
> end do
> end with
>
> --
> Ignacio Ortiz de Z��iga
> [Equipo de Xailer/Xailer team]
> http://www.xailer.com
> http://www.xailer.info
Crhis,
The second loop is not necessary. BTW, I forgot to delete the 'RemoveControl' code on my first submit, but I did it on a second submit. But only the Web based forum does work correctly with message editions.
Regards,

Destroying controls?

Publicado: Vie Jul 29, 2011 11:37 am
por ChrisGillard
Ignacio,
Thanks very much for your help on this.
This is a useful technique that I need to remember.
Chris
"Ignacio Ortiz de Zúñiga" <nonametoavoidspam@xailer.com> wrote in
message news:4e326139$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Chris Gillard escribió el jue, 28 julio 2011 22:02
>> Hi Ignacio,
>>
>> Thanks very much for persevering.
>>
>> Your code errored with array access on the
>> :RemoveControl( :aControls[ 1 ] ) line.
>>
>> I changed to this and it appears to work. The second
>> loop is probably not doing anything.
>>
>> with object ::oEditGroupBox
>> do while Len( :aControls ) > 0
>> :aControls[ 1 ]:End()
>> end do
>> do while Len( :aControls ) > 0
>> :RemoveControl( :aControls[ 1 ] )
>> end do
>> :Redraw()
>> :Refresh()
>> end with
>>
>> Seems to do what I want.
>>
>> If you think thats OK I will go with this?
>>
>> Chris
>>
>>
>> "Ignacio Ortiz de Zúñiga"
>> <nonametoavoidspam@xailer.com> wrote in message
>> news:4e31aadb$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email][/email]
>> > Chris Gillard escribi? el jue, 28 julio 2011
>> > 17:47
>> >> Ignacio,
>> >>
>> >> Thanks for that code.
>> >>
>> >> The loop is reducing the len to aControls to ZERO as
>> it
>> >> should ... good.
>> >>
>> >> But the Groupbox still has the 'image' of the
>> controls
>> >> visible.
>> >>
>> >> I have tried GroupBox:Redraw() & GroupBox:Refresh()
>> >>
>> >> Still the 'image' stays.
>> >>
>> >> When new controls are created, I see the new ones
>> and
>> >> the old ones.
>> >>
>> >> Any thoughts
>> >
>> >
>> > Try this (have not tested):
>> >
>> > with object ::oEditGroupBox
>> > do while Len( :aControls ) > 0
>> > :aControls[ 1 ]:End()
>> > :RemoveControl( :aControls[ 1 ] )
>> > end do
>> > end with
>> >
>> > --
>> > Ignacio Ortiz de Z??iga
>> > [Equipo de Xailer/Xailer team]
>> > http://www.xailer.com
>> > http://www.xailer.info
>
>
> Crhis,
> The second loop is not necessary. BTW, I forgot to delete
> the 'RemoveControl' code on my first submit, but I did it on
> a second submit. But only the Web based forum does work
> correctly with message editions.
> Regards,
> --
> Ignacio Ortiz de Zúñiga
> [Equipo de Xailer/Xailer team]
> http://www.xailer.com
> http://www.xailer.info