Call Delphi method followed by ()

In some code, I met the following call:

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

and I don’t understand the meaning of these two brackets after calling Parse. After implementation, I received ads for each 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;
+4
source share
1 answer

The Parse function returns a reference to the function. You can call this function. Longer equivalent form:

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 intermediate results.

+12
source

All Articles