这是一个完整的例子,如果还不行再来问我
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function ListSort(iP1, iP2: Pointer):Integer;
begin
if PInteger(iP1)^ > PInteger(iP2)^ then
Result := 1
else if PInteger(iP1)^ = PInteger(iP2)^ then
Result := 0
else
Result := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lInt: TList;
iP: PInteger;
procedure showlist;
var
i: Integer;
p: PInteger;
begin
for i := 0 to lInt.Count - 1 do
begin
p := lInt.Items;
ShowMessage(IntToStr(p^));
end;
end;
begin
lInt := TList.Create;
new(iP);
iP^ := 3;
lInt.Add(iP);
New(iP);
iP^ := 1;
lInt.Add(iP);
New(iP);
iP^ := 2;
lInt.Add(iP);
lInt.Sort(ListSort);
showlist;
end;
end.