RBA*_*RBA 4 delphi function-pointers delphi-xe2
我在一些代码中遇到了以下调用:
SQLParser.Parse(qry.SQL.Text)().GetWhereClause
我不理解Parse调用后这两个括号的含义.实施后,我得到了每一个的声明:
TSQLParser = class
public
class function Parse(const ASQL: string): ISmartPointer<TSQLStatement>;
TSQLStatement = class
function GetWhereClause: string;
Run Code Online (Sandbox Code Playgroud)
和
ISmartPointer<T> = reference to function: T;
Run Code Online (Sandbox Code Playgroud)
Nin*_*rry 12
Parse函数返回对函数的引用.你可以调用这个函数.更长的等效形式是:
var
FunctionReference: ISmartPointer<TSQLStatement>;
SQLStatement: TSQLStatement;
begin
{ Parse returns a reference to a function. Store that function reference in FunctionReference }
FunctionReference := TSQLParser.Parse(qry.SQL.Text);
{ The referenced function returns an object. Store that object in SQLStatement }
SQLStatement := FunctionReference();
{ Call the GetWhereClause method on the stored object }
SQLStatement.GetWhereClause();
Run Code Online (Sandbox Code Playgroud)
问题中的一行只是一个较短的版本,它不使用显式变量来存储中间结果.
| 归档时间: |
|
| 查看次数: |
293 次 |
| 最近记录: |