我想知道这在 Delphi 中是否可行(或者是否有一个干净的方法):
type
TSomething = record
X, Y : Integer;
end;
GetSomething( x, y )
-> 返回包含这些值的记录。
...然后你有了这个以 TSomething
作为参数的函数,并且你想将其默认为
function Foo( Something : TSomething = GetSomething( 1, 3 );
编译器在这里抛出一个错误,但是我不确定是否有解决方法!
这可以做到吗?
最佳答案
使用重载:
procedure Foo(const ASomething: TSomething); overload;
begin
// do something with ASomething
end;
procedure Foo; overload;
begin
Foo(GetSomething(1, 3));
end;
关于delphi - Delphi 中 TSomething 的默认参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3750728/