Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.delphi.misc > #103

TList

From "Stark" <franco.jommi@tin.it>
Newsgroups comp.lang.pascal.delphi.misc
Subject TList
Date 2011-11-13 19:17 +0100
Message-ID <4ec009ba$0$1390$4fafbaef@reader1.news.tin.it> (permalink)
Organization TIN.IT (http://www.tin.it)

Show all headers | View raw


A frame containing a row of edits is represented by a TFrameEdit class 
(derived from  a Frame class).
As you can see in the following code, a button let the user add additional 
row of edits to a pane. Each new newRow object created, is also added to a 
TList:

procedure TForm1.BtnAddRowClick(Sender: TObject);
var
  newRow: TFrameEdit;
begin
  newRow := TFrameEdit.Create(Self);  //creating a new instance of TFrame 
Edit
  inc(numRows);
  newRow.Top := lastRow.Top + lastRow.Height;
  newRow.Left := lastRow.Left;
  newRow.Name := 'Row' + inttostr(numRows);
  newRow.Parent := Self;
  lastRow := newRow;

  frmList.Add(newRow);                     // adding object to TList frmList
end;

I also need to let the user remove the rows he created on the panel. I am 
trying to use the following simple proc, but it doesn't work:

procedure TForm1.BtnClearRowClick(Sender: TObject);
var   i: integer;
   aFrame: TFrameEdit;
begin
   for i := frmList.Count - 1 downto 0 do
   begin
      aFrame := TFrameEdit(frmList.Items[I]);
      if aFrame <> nil then
         FreeAndNil(aFrame);
   end;

Suppose 3 rows where created, then the aFrame representing Row3 is cleared 
all right. The attempt to clear Row2 fails with "Invalid pointer operation". 
In fact, the proc is trying to free again the first object in the TList wich 
is Row3. I don't understand why this is not found nil in the "if aFrame <> 
nil"  test, which would avoid the FreAndNil execution where it fails.
Theri is something conceptual which I miss. Can anyone help ?


Back to comp.lang.pascal.delphi.misc | Previous | NextNext in thread | Find similar


Thread

TList "Stark" <franco.jommi@tin.it> - 2011-11-13 19:17 +0100
  Re: TList Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2011-11-13 13:41 -0500
    Re: TList "Stark" <franco.jommi@tin.it> - 2011-11-14 18:09 +0100
      Re: TList Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2011-11-14 17:29 -0500
        Re: TList "Stark" <franco.jommi@tin.it> - 2011-11-15 12:11 +0100
        Re: TList "Maarten Wiltink" <maarten@kittensandcats.net> - 2011-11-17 00:07 +0100

csiph-web