[Lazarus] assigning OnKeyPress at runtime

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Dec 3 07:13:58 CET 2012


On Sun, 2 Dec 2012 16:27:13 -0800 (PST)
Alejandro Gonzalo <parkingspace26 at yahoo.com> wrote:

> I am using Laz 1.04 for Win 7 64 bit.  I get error msg: Error: Incompatible types: got "Pointer" expected "<procedure variable type of procedure(TObject,var Char) of object;Register>"
> 
> 
> this is the procedure in a unit Implemetation section that I want to use for OnKeyPress  (I also put the prototype in the Interface section):
> Procedure Rolodex(Sender: TObject; var Key: char);
>     var myTable : TAdsTable;   // I'm using Advantage Database Systems
>     begin
>     myTable:=TAdsTable(Form1.dbNavigator1.DataSource.Dataset);
>     if ((myTable.State = dsBrowse) AND
>         (Ord(Key) IN [32..126]) AND
>         (myTable.indexname<>'')) then
>       myTable.FindNearest([upcase(Key)]);
>     end;             
>  
> I loop through the form's components (Temp := myForm.Components[i];):
>     if ((Temp is TDBGrid) AND (TDBGrid(Temp).Parent = myPage)) then    
>       TDBGrid(Temp).OnKeyPress := @Rolodex;  //get error this line, also without the @
>  
> This is in a separate unit not associated with a form but I assume that does not matter (the unit is in the main form's Uses list in the Implementation section).
> What did I leave out ?  Any help will be greatly appreciated!

OnKeyPress must be a method, i.e. a procedure of an object.
A normal procedure and a method are not compatible.

Mattias




More information about the Lazarus mailing list