procedure TForm1.Button1Click(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;
=======================================轉載=============================
下文來自 http://fxh7622.blog.51cto.com/63841/29548 原創 (呵呵)
procedure TForm1.Button2Click(Sender: TObject);
const
CardType:array[0..3] of String = ('S','H','D','C');
const
CardNums = 4;
type
RCardrecord = record
CardInfo:String[2];
end;
PCard = ^RCardrecord;
var
t_List:TList;
I:Integer;
t_Sub,t_Spare:Integer;
t_CardType,t_CardNum:String;
p_Card:PCard;
t_Random:Integer;
t_CardInfo:String[8];
Count:Integer;
begin
t_List:=TList.Create; //list
for I:=1 to 52 do
begin
t_Sub:=I div 14; //intger
t_Spare:=I mod 14; //intger
t_CardType:=CardType[t_Sub]; //string array of string := ('S','H','D','C')
t_CardNum:=IntToHex(t_Spare,1); //string
New(p_Card); //^
p_Card.CardInfo:=t_CardType+t_CardNum; //
t_List.Add(p_Card); //list add ^
end;
Randomize;
for I:=1 to CardNums do //for 1 to 4 do
begin
t_Random:=Random(t_List.Count); //int
p_Card:=t_List.Items[t_Random]; //^ := list.items
t_CardInfo:=t_CardInfo+p_Card^.CardInfo;
t_List.Delete(t_Random);
DisPose(p_Card);
end;
Count:=t_List.Count;
for I:=Count-1 downto 0 do
begin
p_Card:=t_List.Items[I];
t_List.Delete(I);
DisPose(p_Card);
end;
t_List.Free;
end;