看一下例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
PTest = ^TTest;
TTest = Array [0..1] of Integer;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ProTest(var ATest: TTest);
procedure ProPTest(var APTest: PTest);
procedure ProStr(AStr: TStringList);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.ProTest(var ATest: TTest);
var
i: Integer;
begin
i:= ATest[0];
ATest[0]:= ATest[1];
ATest[1]:= i;
end;
procedure TForm1.ProStr(AStr: TStringList);
var
S: String;
begin
S:= AStr[0];
AStr[0]:= AStr[1];
AStr[1]:= S;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyTest: TTest;
MyPTest: PTest;
i: Integer;
begin
MyTest[0]:= 1;
MyTest[1]:= 2;
MyPTest:= @MyTest;
ProTest(MyTest);
i:= MyTest[0];
ProPTest(MyPTest);
ShowMessage(IntToStr(i)+ IntToStr(MyPTest^[0]));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MyStr: TStringList;
begin
MyStr:= TStringList.Create;
MyStr.Add('A');
MyStr.Add('B');
ProStr(MyStr);
ShowMessage(MyStr[0]);
MyStr.Free;
end;
procedure TForm1.ProPTest(var APTest: PTest);
var
i: Integer;
begin
i:= APTest^[0];
APTest^[0]:= APTest^[1];
APTest^[1]:= i;
end;
end.