Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 10 of 17 total |
Removing Control |
Thu, Jun 8 2017 8:47 AM | Permanent Link |
Chris Holland SEC Solutions Ltd. Team Elevate | What is the correct way to remove an unwanted control from a form?
I have some TBasicPanels that are sub panels of a question panel and I want to remove them so I did this: for i := QuestionsPanel.ControlCount - 1 downto 0 do begin c := QuestionsPanel.Controls[i]; if c is TBasicPanel then begin c.Free; end; end; But doing this when the form closes and I free the form throws an error. Comment out the c.Free part of the code and the error disappears! -- Chris Holland [Team Elevate] |
Thu, Jun 8 2017 9:16 AM | Permanent Link |
Chris Holland SEC Solutions Ltd. Team Elevate | I found out the problem.
It didn't like it because I had declared c as TComponent instead of TControl. Changed that and it is all working now. Chris Holland [Team Elevate] On 08/06/2017 13:47, Chris Holland wrote: > What is the correct way to remove an unwanted control from a form? > > I have some TBasicPanels that are sub panels of a question panel and I > want to remove them so I did this: > > for i := QuestionsPanel.ControlCount - 1 downto 0 do > begin > c := QuestionsPanel.Controls[i]; > if c is TBasicPanel then > begin > c.Free; > end; > end; > > But doing this when the form closes and I free the form throws an error. > Comment out the c.Free part of the code and the error disappears! > |
Thu, Jun 8 2017 9:18 AM | Permanent Link |
Mark Brooks Slikware | I have a procedure that I use all over the place the clear out the contents of a TScrollPanel:
procedure MCBClearScrollContents(const AScrollPanel: TScrollPanel); var I: integer; C: TControl; begin with AScrollPanel do begin BeginUpdate; try for I := ControlCount - 1 downto 0 do begin C := Controls[I]; C.Parent := nil; Controls[I].Free; end; finally EndUpdate; end; end; end; It seems to me the key difference is that I'm setting the parent to nil? Hope this helps Mark |
Fri, Jun 9 2017 7:24 AM | Permanent Link |
Chris Holland SEC Solutions Ltd. Team Elevate | Hi Mark,
Okay, that helped thanks. It turns out that doing this: C := Controls[I]; C.Free causes it to crash when I close the form, but doing this works: Controls[I].Parent := nil; Controls[i].Free; I have to nil the parent and use the Controls[i].Free in stead of the C.Free or it still crashes! Not sure what the difference is between C := Controls[I]; C.Free and C := Controls[I]; Controls[I].Free but it doesn't like the first one! Chris Holland [Team Elevate] On 08/06/2017 14:18, Mark Brooks wrote: > I have a procedure that I use all over the place the clear out the contents of a TScrollPanel: > > procedure MCBClearScrollContents(const AScrollPanel: TScrollPanel); > var > I: integer; > C: TControl; > begin > with AScrollPanel do > begin > BeginUpdate; > try > for I := ControlCount - 1 downto 0 do > begin > C := Controls[I]; > C.Parent := nil; > Controls[I].Free; > end; > finally > EndUpdate; > end; > end; > end; > > It seems to me the key difference is that I'm setting the parent to nil? > > Hope this helps > Mark > |
Fri, Jun 16 2017 1:00 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Chris,
<< It didn't like it because I had declared c as TComponent instead of TControl. Changed that and it is all working now. >> That shouldn't make any difference - the TControl is a TComponent descendant class. How were the controls being created ? Manually, or as part of the form load ? Tim Young Elevate Software www.elevatesoft.com |
Sun, Jun 18 2017 3:49 PM | Permanent Link |
Chris Holland SEC Solutions Ltd. Team Elevate | Hi Tim,
They were all created manually. Chris Holland [Team Elevate] On 16/06/2017 18:00, Tim Young [Elevate Software] wrote: > Chris, > > << It didn't like it because I had declared c as TComponent instead of TControl. > > Changed that and it is all working now. >> > > That shouldn't make any difference - the TControl is a TComponent descendant class. > > How were the controls being created ? Manually, or as part of the form load ? > > Tim Young > Elevate Software > www.elevatesoft.com > |
Mon, Jun 19 2017 1:46 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Chris,
<< They were all created manually. >> I'm still not seeing any issues here. This is the code I'm using: procedure TForm1.Button2Click(Sender: TObject); var I: Integer; begin for I:=1 to 4 do TBasicPanel.Create(Self); end; And then your code for deletion: procedure TForm1.Button1Click(Sender: TObject); var i: Integer; c: TComponent; begin for i := ControlCount - 1 downto 0 do begin c := Controls[i]; if c is TBasicPanel then begin c.Free; end; end; end; I just want to make sure that I'm not missing something here... Tim Young Elevate Software www.elevatesoft.com |
Tue, Jun 20 2017 4:28 AM | Permanent Link |
Matthew Jones | Tim Young [Elevate Software] wrote:
> I just want to make sure that I'm not missing something here... The key is in the line "doing this when the form closes and I free the form throws an error" in my experience. Things get hairy when things are closing, as you can easily remove something that then gets referenced later in the chain. The Chrome debugger usually tells me what I did wrong quite quickly. -- Matthew Jones |
Tue, Jun 20 2017 12:59 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Matthew,
<< The key is in the line "doing this when the form closes and I free the form throws an error" in my experience.>> Yeah, but I'm doing that. I'm running this in the browser debugger to ensure that I see any shutdown errors that, typically, a lot of browsers suppress (but show in the console) because it just wants an orderly shutdown. Tim Young Elevate Software www.elevatesoft.com |
Wed, Jun 28 2017 3:35 AM | Permanent Link |
Mark Brooks Slikware | Mark Brooks wrote:
I have a procedure that I use all over the place the clear out the contents of a TScrollPanel: procedure MCBClearScrollContents(const AScrollPanel: TScrollPanel); var I: integer; C: TControl; begin with AScrollPanel do begin BeginUpdate; try for I := ControlCount - 1 downto 0 do begin C := Controls[I]; C.Parent := nil; Controls[I].Free; end; finally EndUpdate; end; end; end; It seems to me the key difference is that I'm setting the parent to nil? Hope this helps Mark Tim - is this procedure ok - do I need to set the Parent to nil - thanks |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Sunday, May 5, 2024 at 07:30 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |