Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi method call followed by ()

I've encountered in some code the following call :

SQLParser.Parse(qry.SQL.Text)().GetWhereClause

and I don't understand the meaning of those 2 parenthesis after the Parse call. Following the implementation I got the declarations for each one of them:

 TSQLParser = class
  public
    class function Parse(const ASQL: string): ISmartPointer<TSQLStatement>;

  TSQLStatement = class
    function GetWhereClause: string;

and

  ISmartPointer<T> = reference to function: T;
like image 269
RBA Avatar asked Dec 15 '22 05:12

RBA


1 Answers

The Parse function returns a reference to a function. You can call this function. A longer equivalent form would be:

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();

The line in the question is just a shorter version that does not use explicit variables to store the intermediate results.

like image 189
NineBerry Avatar answered Dec 22 '22 00:12

NineBerry