rotursoft
rotursoft

Reputation: 31

Delphi ambiguous call of functions

I need to find out where can be wrong function called.

I use this construct for years in thousands of places:

var mQuery:TIBOQuery;
begin
  mQuery := CreateQuery(FirebirdTransaction);
  try
    with mQuery, mQuery.SQL do begin
      Clear;
      Add('SELECT POKLADNA FROM HOMEBANKING_EXPORT_POLOZKY WHERE POKLADNA = :JEDIN');
      ParamByName('JEDIN').Value := Jedin;
      Open;
      Result := Active and not IsEmpty;
      Close;
    end;
  finally
    mQuery.Free;
  end;
end;

Actually I am working on upgrade from Delphi 11.3 to 12.1, but Embarcadero added function TStrings.IsEmpty in Delphi.Athens and it makes a problem on many places where I expect to call TDataSet.IsEmpty instead of TStrings.IsEmpty from "mQuery.SQL".

Is it possible to turn on some compiler mechanism which will rather not compile this project than to simply compile with many "surprises" of ambiguous calls?

Upvotes: 1

Views: 313

Answers (1)

Pieter B
Pieter B

Reputation: 1967

If you want to resolve ambiguous call you should stop using "with"

var mQuery:TIBOQuery;
begin
  mQuery := CreateQuery(FirebirdTransaction);
  try
    mQuery.SQL.Clear;
    mQuery.SQL.Add('SELECT POKLADNA FROM HOMEBANKING_EXPORT_POLOZKY WHERE POKLADNA = :JEDIN');
    mQuery.ParamByName('JEDIN').Value := Jedin;
    mQuery.Open;
    Result := mQuery.Active and not mQuery.IsEmpty;
    mQuery.Close;
  finally
    mQuery.Free;
  end;
end;

The added benefit is that you now can inspect your variables while debugging.

Upvotes: 4

Related Questions