[DUG] Stringgrid - intercepting keys

John Bird johnkbird at paradise.net.nz
Mon Oct 5 17:25:52 NZDT 2009


For a long time I have been intercepting keys such as Escape/Enter/Tab no 
problem

I have been wanting to put a simple search facility in a string grid, and 
would like to intercept Ctrl/F and F3.....but the code as I am using does 
not get them (D2007) - they are just ignored.

Looks like the only characters I can intercept are Tab, Enter and Escape...

Any suggestions?


procedure TfrmTimeSh2.CMDialogKey(var Msg: TWMKEY);
{
   This converts ENTER key messages to TAB key messages, provided a few
   conditions hold
}
begin
   if   (ActiveControl is TCustomEdit)
    or (ActiveControl is TStringGrid)
   then
     begin
       ATPKeyDir:='';
       if Msg.CharCode = VK_RETURN then
       begin
         Msg.CharCode := VK_TAB;
         ATPKeyDir:='Next';
       end;
       if Msg.Charcode = VK_ESCAPE then
       begin
         Msg.CharCode := VK_TAB;
         ATPKeyDir:='Prev';
       end;
       if Msg.Charcode = VK_F2 then                            <===  never 
intercepted
       begin
         xcGridFind((ActiveControl as TStringGrid),FindStr,strFound);
       end;
       if Msg.Charcode = VK_F3 then              <===  never intercepted
       begin
         xcGridFindNext((ActiveControl as TStringGrid),FindStr,strFound);
       end;
     end;
   inherited;
end;


John 




More information about the Delphi mailing list