Note that there are some explanatory texts on larger screens.

plurals
  1. POIs Delphi "with" keyword a bad practice?
    text
    copied!<p>I been reading bad things about the <strong>with</strong> keyword in delphi but, in my opinion, if you don't over use it. It can make your code look simple.</p> <p>I often put all my TClientDataSets and TFields in TDataModules. So in my forms I had code like this</p> <pre><code>procedure TMyForm.AddButtonClick(Sender: TObject); begin with LongNameDataModule do begin LongNameTable1.Insert; LongNameTable1_Field1.Value := "some value"; LongNameTable1_Field2.Value := LongNameTable2_LongNameField1.Value; LongNameTable1_Field3.Value := LongNameTable3_LongNameField1.Value; LongNameTable1_Field4.Value := LongNameTable4_LongNameField1.Value; LongNameTable1.Post; end end; </code></pre> <p>without the <strong>with</strong> keyword I have to write the code like this</p> <pre><code> procedure TMyForm.AddButtonClick(Sender: TObject); begin LongNameDataModule.LongNameTable1.Insert; LongNameDataModule.LongNameTable1_LongNameField1.Value := "some value"; LongNameDataModule.LongNameTable1_LongNameField2.Value := LongNameDataModule.LongNameTable2_LongNameField1.Value; LongNameDataModule.LongNameTable1_LongNameField3.Value := LongNameDataModule.LongNameTable3_LongNameField1.Value; LongNameDataModule.LongNameTable1_LongNameField4.Value := LongNameDataModule.LongNameTable4_LongNameField1.Value; LongNameDataModule.LongNameTable1.Post; end; </code></pre> <p>I think is easier to read using the <strong>with</strong> keyword.</p> <p>Should I avoid using the <strong>with</strong> keyword?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload