[英]Delphi - Inline object declaration and assigning properties in a function call
I was just wondering if a construct like the following c# function call is possible in Delphi: 我只是想知道在Delphi中是否可以进行类似以下c#函数调用的构造:
C# code: C#代码:
MyFunction(Param1, new MyClass() {property1 = "value1", property2 = true, property3 = 100}, Param3);
As for now in Delphi I should do the following to get that result: 到目前为止,在Delphi中,我应该执行以下操作以获得该结果:
Delphi code: Delphi代码:
var
aMyClass: TMyClass;
begin
aMyClass:= TMyClass.Create;
aMyClass.property1:= 'value1';
aMyClass.property2:= True;
aMyClass.property3:= 100;
MyFunction(Param1, aMyClass, Param3);
end;
Much more verbose. 更详细。
Help appreciate. 帮助欣赏。
在Delphi中,达到类似简洁的唯一方法是定义一个带有参数的构造函数以接收属性值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.