Explorer060599
asked on
route OnKeyPress event to procedure
hi experts, i would like to route all TWinControl control's OnKeyPress event to my local procedure as follow. why it's error "undeclared identifier: 'OnKeyPress' ? isn't TWinControl the base class of this event ?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
procedure ev_OnKeyPress(Sender: TObject; var Key: Char);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
wc : TWinControl;
t : TList;
i : Integer;
begin
t := TList.Create;
try
t.Add(Edit1);
t.Add(Button1);
for i := 0 to t.Count -1 do
TWinControl(t[i]).OnKeyPre ss := ev_OnKeyPress;
finally
t.Free;
t := nil;
end;
end;
procedure TForm1.ev_OnKeyPress(Sende r: TObject; var Key: Char);
begin
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
procedure ev_OnKeyPress(Sender: TObject; var Key: Char);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
wc : TWinControl;
t : TList;
i : Integer;
begin
t := TList.Create;
try
t.Add(Edit1);
t.Add(Button1);
for i := 0 to t.Count -1 do
TWinControl(t[i]).OnKeyPre
finally
t.Free;
t := nil;
end;
end;
procedure TForm1.ev_OnKeyPress(Sende
begin
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So you might have to do this
if (t[i] is TEdit) then
TEdit(t[i]).OnKeyPress := ev_OnKeyPress
else ...
HTH
DragonSlayer