是否可以使用记录作为方法参数,并在不隐式声明所述记录的实例的情况下调用它?
我希望能够编写这样的代码。
type
TRRec = record
ident : string;
classtype : TClass;
end;
procedure Foo(AClasses : array of TRRec);
然后调用这样的方法或类似的方法。
Foo([('Button1', TButton), ('Lable1', TLabel)]);
顺便说一句,我仍然停留在 Delphi 5 上。
最佳答案
是的。差不多了。
type
TRRec = record
ident : string;
classtype : TClass;
end;
function r(i: string; c: TClass): TRRec;
begin
result.ident := i;
result.classtype := c;
end;
procedure Foo(AClasses : array of TRRec);
begin
;
end;
// ...
Foo([r('Button1', TButton), r('Lable1', TLabel)]);
关于delphi - delphi 中的匿名记录构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/614536/