 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mike McWhinney Guest
|
Posted: Mon Feb 23, 2004 7:33 pm Post subject: OnKeyDown handler inside messagedialog form |
|
|
Hello,
I have a custom form/dialog created at runtime which is a custom form
based on CreateMessageDialog.
I am trying to use the OnKeyDown event to create an event when the
pgup key is pressed. However I am having problems implementing it. On
compiling the statement: OnkeyDown:=YNFormKeyDown I get an error message:
Incompatible types: method pointer and regular procedure
How can this procedure set up a keydown handler so that keypresses can be
trapped?
Thanks in advance.
Mike
Procedure GetYNDialog(S:String; Var Yes:Boolean);
Var
Res:Word;
YNForm:TForm;
btn:TButton;
tlab:TLabel;
procedure YNFormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If key=VK_PRIOR then Begin
YNForm.ModalResult:=mrCancel;
showmessage('pgup pressed');
Key:=0;
End;
end;
Begin
YNForm:=CreateMessageDialog(S,mtConfirmation,
[mbYes,mbNo,mbCancel]);
YNForm.Caption:='';
YNForm.borderstyle:=bsdialog;
YNForm.BorderIcons:=[];
YNForm.Color:=$0086B9BB;
YNForm.Font.Name:='Arial';
YNForm.Font.Size:=16;
YNForm.Height:=340;
YNForm.Width:=360;
tlab:=TLabel(YNForm.Components[1]);
tlab.width:=250;
With YNForm do Begin
BorderIcons:=BorderIcons-[biSystemMenu];
If Yes then
activecontrol:=TButton(Components[2])
else
activecontrol:=TButton(Components[3]);
btn:=TButton(Components[2]);
btn.left:=50;
btn.top:=145;
btn.width:=85;
btn.height:=85;
btn:=TButton(Components[3]);
btn.left:=200;
btn.top:=145;
btn.width:=85;
btn.height:=85;
btn:=TButton(Components[4]);
btn.visible:=FALSE;
keypreview:=TRUE;
OnKeyDown:=YNFormKeyDown;
End;
Res:=YNForm.ShowModal;
Yes:=(Res=mrYes);
End;
|
|
| Back to top |
|
 |
Jamie Guest
|
Posted: Tue Feb 24, 2004 10:30 am Post subject: Re: OnKeyDown handler inside messagedialog form |
|
|
create a method procedure.
it must be the same type of OnKeyDown event object that you
nornally would see if done via the IDE method..
this procedure proto type (header) will have an entry in the
object of the public settion.
then you create the actuall event procedure in code like this.
mydialogExxxxxx.OnKeyOPress(Sender:TObject, and the rest of the
expected params.).
---
Mike McWhinney wrote:
| Quote: | Hello,
I have a custom form/dialog created at runtime which is a custom form
based on CreateMessageDialog.
I am trying to use the OnKeyDown event to create an event when the
pgup key is pressed. However I am having problems implementing it. On
compiling the statement: OnkeyDown:=YNFormKeyDown I get an error message:
Incompatible types: method pointer and regular procedure
How can this procedure set up a keydown handler so that keypresses can be
trapped?
Thanks in advance.
Mike
Procedure GetYNDialog(S:String; Var Yes:Boolean);
Var
Res:Word;
YNForm:TForm;
btn:TButton;
tlab:TLabel;
procedure YNFormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If key=VK_PRIOR then Begin
YNForm.ModalResult:=mrCancel;
showmessage('pgup pressed');
Key:=0;
End;
end;
Begin
YNForm:=CreateMessageDialog(S,mtConfirmation,
[mbYes,mbNo,mbCancel]);
YNForm.Caption:='';
YNForm.borderstyle:=bsdialog;
YNForm.BorderIcons:=[];
YNForm.Color:=$0086B9BB;
YNForm.Font.Name:='Arial';
YNForm.Font.Size:=16;
YNForm.Height:=340;
YNForm.Width:=360;
tlab:=TLabel(YNForm.Components[1]);
tlab.width:=250;
With YNForm do Begin
BorderIcons:=BorderIcons-[biSystemMenu];
If Yes then
activecontrol:=TButton(Components[2])
else
activecontrol:=TButton(Components[3]);
btn:=TButton(Components[2]);
btn.left:=50;
btn.top:=145;
btn.width:=85;
btn.height:=85;
btn:=TButton(Components[3]);
btn.left:=200;
btn.top:=145;
btn.width:=85;
btn.height:=85;
btn:=TButton(Components[4]);
btn.visible:=FALSE;
keypreview:=TRUE;
OnKeyDown:=YNFormKeyDown;
End;
Res:=YNForm.ShowModal;
Yes:=(Res=mrYes);
End;
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|