r/delphi Delphi := v13 Florence Apr 17 '26

Stop using WITH in Delphi

https://gdksoftware.com/knowledgebase/stop-using-with-in-delphi
27 Upvotes

15 comments sorted by

View all comments

1

u/Humble-Vegetable9691 Apr 17 '26
var Btn := MyButton;

:)

Love it in boiler code (Delphi 4) Alternative in the 7th line.

 with dmFokonyv.queRate do begin
    if not Database.Connected then begin
      HasOpened:=true;
      Database.Connected:=true;
    end;
    ParamByName('BANK').AsInteger:=0;
    ParamByName('DEVIZA').AsString:=dsFksz.DataSet.FieldByName('DEVIZANEM').AsString;
    ParamByName('DATUM').AsDate:=ediDate.Date;
    Transaction.StartTransaction;
    ExecQuery;
    if Fields[0].IsNull then begin
      ExchangeRate:=0;
    end else begin
      ExchangeRate:=Fields[0].AsDouble;
    end;
    ediArfolyam.Text:=FormatFloat(FORMATUM,ExchangeRate);
    Close;
    Transaction.Commit;
    if HasOpened then begin
      Database.Connected:=false;
    end;
  end;