I've built a custom control that is supposed to have an access key. That is, in the text part of the control one of the letters is underlined when the keyboard is being used for navigation and pressing the access key should focus the control.
The problem is that pressing the access key doesn't do anything. I'm not especially surprised because I haven't written any code to make this happen. But I've scoured MSDN and Stack Overflow and can't find any information telling me how to do this.
Can someone please point me in the right direction? I'm guessing I need to respond to a message from the window manager to tell it what access keys my control should respond to, and I'm also guessing there's a WinApi function somewhere that extracts an access key from a string such as "&Commit".
You have to implement a Messagehandler for CM_DialogChar to your component.
The example here is using a interposer class for demonstration with a hard coded '&Hallo'
TShape=Class(Extctrls.TShape)
procedure CMDialogChar(var Message: TCMDialogChar);message CM_DialogChar;
End;
TForm5 = class(TForm)
Shape1: TShape;
Label1: TLabel;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TShape.CMDialogChar(var Message: TCMDialogChar);
begin
if IsAccel(Message.CharCode, '&Hallo') then
begin
Showmessage('Hallo');
Message.Result := 1;
end;
end;