delphi - Delphi 中 TSomething 的默认参数值

标签 delphi parameters default-parameters

我想知道这在 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/

相关文章:

delphi - Delphi 中对象的字符串共享/引用问题

ios - Delphi/Firemonkey 在运行时更改 iOS 屏幕旋转

sql - 在 Delphi SQL 参数中插入字段名称而不是字符串

Swift func参数奇怪

python - 当 'None' 或没有传递参数时,如何接受函数中的默认参数?

swift - 传入值为 nil 的函数参数的默认值

delphi - 为什么添加到 ImageList 时图片会失去质量?

delphi - 如何使表单可见并最大化以填充辅助监视器而不激活它?

bash - 将 bash 脚本参数拆分为 "="

c# - 编译器错误 "Default parameter specifiers are not permitted"