首页 > Windows开发 > 详细

delphi 匿名方法访问var参数

时间:2020-05-26 17:26:37      阅读:57      评论:0      收藏:0      [点我收藏+]

https://community.idera.com/developer-tools/general-development/f/rad-studio-general/72305/anonymous-methods-acessing-var-parameters
Anonymous methods acessing var parameters
Hi there

Is it possible to access or set the content of a var parameter inside a anonymous method? When I try this code below, the compiler doesn‘t recognize the variabel Value.

procedure TForm1.OnGetValue(var Value: Double);
begin
  Form2:=TForm2.Create(nil);
  Form2.ShowModal(procedure(AResult: TModalResult)
  begin
    if AResult=mrOK then
      Value:=Form2.FValue;
  end);
end;

Hi, try this

procedure TForm1.OnGetValue(var Value: Double);
var
  X : Double;
begin
  Form2 := TForm2.Create(Nil);
  Form2.ShowModal(
    procedure(AResult: TModalResult)
    begin
    if AResult=mrOK then
       X:=Form2.FValue;
    end);
  Value:=X;
end;

or this

procedure TForm1.OnGetValue(var Value: Double);
var
  X : PDouble;
begin

x:=@Value;
  Form2 := TForm2.Create(Nil);
  Form2.ShowModal(
    procedure(AResult: TModalResult)
    begin
    if AResult=mrOK then
       X^:=Form2.FValue;
    end);
end;

delphi 匿名方法访问var参数

原文:https://www.cnblogs.com/marklove/p/12966302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!