type
TMyArr = array [0..3] of TPoint;
PMyArr = ^TMyArr;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure ShowArr(P:Pointer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyArr : array [0..3] of TPoint ;
begin
MyArr[0].X := 0 ;
MyArr[0].Y := 0 ;
MyArr[1].X := 1 ;
MyArr[1].Y := 1 ;
MyArr[2].X := 2 ;
MyArr[2].Y := 2 ;
MyArr[3].X := 3 ;
MyArr[3].Y := 3 ;
ShowArr(@MyArr[0]);
end;
procedure TForm1.ShowArr(P: Pointer);
var
MyArr:PMyArr;
begin
MyArr := PMyArr(P);
Showmessage(Inttostr(MyArr^[2].X));
end;
数组固定,也可以定义固定数组的类型,来设置。
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyArr = array of TPoint;
PMyArr = ^TMyArr;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure ShowArr(P:Pointer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MyArr : array of TPoint ;
begin
setlength(MyArr,4) ;
MyArr[0].X := 0 ;
MyArr[0].Y := 0 ;
MyArr[1].X := 1 ;
MyArr[1].Y := 1 ;
MyArr[2].X := 2 ;
MyArr[2].Y := 2 ;
MyArr[3].X := 3 ;
MyArr[3].Y := 3 ;
ShowArr(@MyArr);
end;
procedure TForm1.ShowArr(P: Pointer);
var
MyArr:PMyArr;
begin
MyArr := PMyArr(P);
Showmessage(Inttostr(MyArr^[2].X));
end;