我有这个代码,有一个使用重载和默认参数的过程:
program Project2;
{$APPTYPE CONSOLE}
uses SysUtils;
procedure Foo; overload; // not actually needed to reproduce
begin
end;
procedure Foo(const a: array of string; b: Boolean=False); overload;
begin
Writeln(Length(a));
end;
begin
Foo(['1', '2', '3']); // => 1 ???
Foo(['1', '2', '3'], False); // => 3 OK
Readln;
end.
Run Code Online (Sandbox Code Playgroud)
输出是:
1
3
Run Code Online (Sandbox Code Playgroud)
请注意,第一次调用 Foo不提供默认值。为什么会这样?这个问题只与非常旧的编译器有关吗?
这仅在使用overload密钥时发生。
procedure Foo2(const a: array of string; b: Boolean=False);
begin
Writeln(Length(a));
end;
Foo2(['1', '2', '3']);
Run Code Online (Sandbox Code Playgroud)
工作正常。
我有以下 SQL 命令来运行TFDQuery使用 PostgreSQL 作为数据库的查询:
fdqr.SQL.Text: =
'select * from (values (current_date-1), (current_date), (current_date + 1)) as t (datetest) ' +
'{iif (! Datevalue, where datetest =! Datevalue)}';
Run Code Online (Sandbox Code Playgroud)
当我使用该Clear方法清除宏值时,我希望解释脚本以便消除过滤器,但事实并非如此。
fdqr.MacroByName('datevalue').Clear;
fdqr.Open;
Run Code Online (Sandbox Code Playgroud)
结果数据库日志:
fdqr.SQL.Text: =
'select * from (values (current_date-1), (current_date), (current_date + 1)) as t (datetest) ' +
'{iif (! Datevalue, where datetest =! Datevalue)}';
Run Code Online (Sandbox Code Playgroud)
但是,如果您通过 包含赋值AsRaw,它会按预期工作,即使先前的值是''(空字符串)并且IsNull是True。
fdqr.MacroByName('datevalue').Clear;
{ at this point IsNull = True and AsRaw is …Run Code Online (Sandbox Code Playgroud)