[Solved] Assigning Event handler at Run-Time? lazarus / 31-LCL ---------------------------------------------------------------------- Avishai · 2013-05-17 04:36 I have create a TStringGrid in Run-Time and need to assign procedure OnGetEditText event handler.  What is the syntax for this? Code: [Select]var   Junk: String: procedure TForm1.FormCreate(Sender: TObject);   AGrid:= TStringGrid.Create(Self);   with AGrid do begin     Parent:= APageCtrl.Pages[0];     Width:= 250;     Height:= 120;     Left:= 16;     Top:= 200;     Options:= ([goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine, goRangeSelect,goEditing,goSmoothScroll]);     AutoAdvance:= aaRightDown;     Junk:= '';     //This is not right.     OnGetEditText:= Self.AGridGetEditText(Sender, Col, Row, Junk);    end; end; procedure TForm1.AGridGetEditText(Sender: TObject; ACol, ARow: Integer;   var Value: string); begin   with Sender as TStringCellEditor do     TStringCellEditor(Sender).BiDiMode:= bdRightToLeft; end; ---------------------------------------------------------------------- User137 · 2013-05-17 04:39 Code: [Select]OnGetEditText:=@AGridGetEditText;(With or without self. works in this case.) ---------------------------------------------------------------------- Avishai · 2013-05-17 04:48 That's what I thought too but I get RunError(219). ---------------------------------------------------------------------- taazz · 2013-05-17 05:04 based on http://www.freepascal.org/docs-html/user/userap4.html 219 is invalid cast, to me this seems like 1) you still have everything in that line if you do then please remove everything from the parenthesis on eg from Code: [Select]OnGetEditText:= @AGridGetEditText(Sender, Col, Row, Junk); to Code: [Select]OnGetEditText:= @AGridGetEditText; or 2) the line you see as problematic is not the one raising the problem. In this case I think that the code inside the event handler causes the exception. try the following code. Code: [Select]procedure TForm1.AGridGetEditText(Sender: TObject; ACol, ARow: Integer;   var Value: string); begin   if Sender is TStringCellEditor then     TStringCellEditor(Sender).BiDiMode:= bdRightToLeft; end; ---------------------------------------------------------------------- Avishai · 2013-05-17 05:29 OK.  This works.  Thanks guys.  I think it's time I went to bed   I should not have made that mistake to start with and then the more I tried to fix it, the worse it got. Code: [Select]OnGetEditText:= @AGridGetEditText; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState   ); begin   if Sender is TStringGrid then     TStringGrid(Sender).InplaceEditor.BiDiMode:= bdRightToLeft; end; ---------------------------------------------------------------------- BigChimp · 2013-05-17 06:06 Good night