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;