[SOLVED]TStringGrid.SelectEditor not selecting editor when with..do is used lazarus / 31-LCL ---------------------------------------------------------------------- goldenfox · 2012-05-30 01:24 I don't know what's wrong but using "with tstringgrid do" will not set Edit1 as editor in TStringGrid.SelectEditor. Did I miss something here? Please refer to my attached source. Thanks. ---------------------------------------------------------------------- Zoran · 2012-05-30 07:22 This: Code: [Select]  with StringGrid1 do   if ( aRow > 0 ) then   begin     Edit1.BoundsRect := CellRect(aCol,aRow);     Edit1.Text := Cells[aCol,aRow];     Editor := Edit1; // -- Editor is not the parameter here, but Grid's property!   end; does not work, because Grid has the property of same name - Editor. So, when you enclose the code in "with" block, the property name takes precedence over the method's var parameter. Compiler understands last line as if it is "StringGrid1.Editor := Edit1;". This works: Code: [Select]  if ( aRow > 0 ) then begin     with StringGrid1 do begin       Edit1.BoundsRect := CellRect(aCol,aRow);       Edit1.Text := Cells[aCol,aRow];     end;     Editor := Edit1;   end; This is a nice illustration of the dangerous side effects of using "with" in object pascal. Never enclose in "with" block more than actually needed! Use "with" with care, avoid it as much as possible. ---------------------------------------------------------------------- goldenfox · 2012-05-30 08:29 @Zoran: Thanks for the tip.