Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

assigning OnKeyPress at runtime

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alejandro Gonzalo

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! ?
A. G.

Reply by email

Mattias Gaertner
to Alejandro Gonzalo
Show quoted text 20 lines
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

Reply by email