Recent

Author Topic: [SOLVED] OnKeyDown and dynamic TEdit controls  (Read 2618 times)

ranlaborde

  • New Member
  • *
  • Posts: 11
[SOLVED] OnKeyDown and dynamic TEdit controls
« on: September 04, 2017, 10:36:21 am »
I have a series of TEdit controls that I have created dynamically.  I have two procedures, OnClick and OnDblClick, that work on each of the dynamically created controls (Thanks Zoran (ButArr.Zip).  I wish to add OnKeyDown to work on each control.  The code is as follows:


    { private declarations }
    procedure EKeyDown(Sender: TObject);

procedure TForm1.FormCreate(Sender: TObject);
var
  E: TEdit;
  ctr2: Integer;
begin
   for ctr2:= 0 to V - 1 do
    begin
      E:= TEdit.Create(Self);
      E.Tag:= Length(EdArray) + 1;
      E.OnClick:= @EClick;
      E.OnDblClick:= @EDblClick;
      E.OnKeyDown:= @EKeyDown;
      E.Autosize:= False;
      E.CharCase:= ecUpperCase;
      E.MaxLength:= 1;
      E.Alignment:= taCenter;
      E.Font.Size:= 14;
      E.Width:= 36;
      E.Height:= 35;
      E.Top:= Tp;
      Hz:= Hz+ 34;
      E.Left:= Hz;
      E.Parent:= Self;
      SetLength(EdArray, Length(EdArray) + 1);
      EdArray[High(EdArray)] := E;
end;

I get the following error at     E.OnKeyDown:= @EKeyDown;
unit1.pas(90,21) Error: Incompatible types: got "<procedure variable type of procedure(TObject) of object;Register>" expected "<procedure variable type of procedure(TObject;var Word;TShiftState) of object;Register>"

what do I need to code after @KeyDown to make this work?  Is the error at @KeyDown or am I declaring it incorrectly (e.g.     procedure EKeyDown(Sender: TObject); ... or do I have errors in both locations?

BTW, the Click and DblClick (shown above) work fine.

Thanks for any help.

The suggewstion was spot on!
« Last Edit: September 04, 2017, 12:02:25 pm by ranlaborde »

RAW

  • Hero Member
  • *****
  • Posts: 871
Re: OnKeyDown and dynamic TEddit controls
« Reply #1 on: September 04, 2017, 10:50:53 am »
Try this...
Code: Pascal  [Select][+][-]
  1. procedure EKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

 

TinyPortal © 2005-2018