delphi @ 与 ^ 运算符
@ 与 ^ 运算符
//例1:
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
p: Pointer;
begin
p := @str; //变量 str 的地址
p := @Form1; //变量 Form1 的地址
p := @TForm1.Button1Click; //过程 TForm1.Button1Click 的地址
p := Addr(str); //同 p := @str;
ShowMessage(IntToStr(Integer(p))); //显示
end;
//例2:
procedure TForm1.Button1Click(Sender: TObject);
var
i1,i2: Integer;
pi: ^Integer;
begin
i1 := 6;
pi := @i1;
if pi<>nil then i2 := pi^;
//if Assigned(pi) then i2 := pi^; //等价与上一句
ShowMessage(IntToStr(i2)); //返回:6
end;
//例1:
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
p: Pointer;
begin
p := @str; //变量 str 的地址
p := @Form1; //变量 Form1 的地址
p := @TForm1.Button1Click; //过程 TForm1.Button1Click 的地址
p := Addr(str); //同 p := @str;
ShowMessage(IntToStr(Integer(p))); //显示
end;
//例2:
procedure TForm1.Button1Click(Sender: TObject);
var
i1,i2: Integer;
pi: ^Integer;
begin
i1 := 6;
pi := @i1;
if pi<>nil then i2 := pi^;
//if Assigned(pi) then i2 := pi^; //等价与上一句
ShowMessage(IntToStr(i2)); //返回:6
end;