Delphi帮助里面的,参考一下吧: procedure TForm1.FormButton1Click(Sender: TObject);type PMyList = ^AList; AList = record I: Integer; C: Char; end;var MyList: TList; ARecord: PMyList; B: Byte; Y: Word; begin MyList := TList.Create; try New(ARecord); ARecord^.I := 100; ARecord^.C := 'Z'; MyList.Add(ARecord); {Add integer 100 and character Z to list} New(ARecord); ARecord^.I := 200; ARecord^.C := 'X'; MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox} Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I} Y := Y + 30; {Increment Y Value again} Canvas.TextOut(10, Y, ARecord^.C); {Display C} Y := Y + 30; {Increment Y Value} end; { Cleanup: must free the list items as well as the list } for B := 0 to (MyList.Count - 1) do begin ARecord := MyList.Items[B]; Dispose(ARecord); end; finally MyList.Free; end; end;
不知道TList和记录怎么发生关系的。
procedure TForm1.FormButton1Click(Sender: TObject);type
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;var MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
try
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Add integer 100 and character Z to list}
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox}
Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; {Increment Y Value again}
Canvas.TextOut(10, Y, ARecord^.C); {Display C}
Y := Y + 30; {Increment Y Value}
end; { Cleanup: must free the list items as well as the list }
for B := 0 to (MyList.Count - 1) do
begin ARecord := MyList.Items[B];
Dispose(ARecord);
end;
finally
MyList.Free;
end;
end;
最近的帖子都是一百分,只有一个是20分的。List.Items[i].婚否 := Yes;
(List.Items[i])^.婚否 := Yes;
这两个哪个正确?
ARecord := MyList.Items[B];
Arecord.XXX := 要修改的值
这样MyList里面的值才变了。而且只有到不使用这个MyList的时候才可以dispose掉ARecord.就象例子里面这样。
for B := 0 to (MyList.Count - 1) do
begin ARecord := MyList.Items[B];
Dispose(ARecord);
end;也就是说,TList有一个add,必须有一个new.如果要add一百个,就要new一百次。各位大侠,我上面理解的对不对?我刚才new一个ARecord然后add到list里面,然后disPose这个ARecord,结果全乱了!感到很困惑的一个问题是:
ARecord := MyList.Items[1];
ARecord := MyList.Items[2];
是不是上面的两个ARecord的指针不是在一个位置?但MyList.Items[1], MyList.Items[2]等指针,在程序运行中是不变的?
Arecord.XXX := 要修改的值>>ARecord := MyList.Items[1];
ARecord := MyList.Items[2];
是不是上面的两个ARecord的指针不是在一个位置?但MyList.Items[1], MyList.Items[2]等指针,在程序运行中是不变的?当然指的不是一个位置了
你第二次赋值的时候,就把前一个指针覆盖了