Link to home
Start Free TrialLog in
Avatar of henryreynolds
henryreynoldsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Delphi form overriding form inheritance

Good day

I have frmMain and frmCapture that are inherited from frmMain.

In frMain on key press event I call forms depending on the short cut key.

But when frmCapture are visible, then frmCapture must ignore the key press event that happens in frmMain, or it must ignore the VK_F5 key.

Is this possible.
Avatar of Geert G
Geert G
Flag of Belgium image

in frmMain you are using KeyPreview ?
in frmCapture set it off

or provide a little more code so we can see what you ment ...
Like Geert suggests, set frmMain.KeyPreview to true
in frmMain, change the Key to 0 after you've handled it:
procedure frmMain.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 // do what you want to do with the key
 Key := 0; // stops other controls from handling it
end;

Open in new window

Avatar of henryreynolds

ASKER

in frmMain I have the following

procedure TfrmMain.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if Key = VK_F3 then
   begin
      Application.CreateForm(TfrmAlphaSearch, frmAlphaSearch);
      try
         frmAlphaSearch.ShowModal();
      finally
         frmAlphaSearch.Free;
      end;
   end;


   if Key = VK_F5 then
   begin
         Application.CreateForm(TfrmSettlements, frmSettlements);
         try
            frmSettlements.ShowModal();
         finally
            frmSettlements.Free;
         end;
    end;
end;

When I am in frmSettlements I dont want to allow F5 -> to call again frmSettlements because I get a acess violation.

thanx
> When I am in frmSettlements I dont want to allow F5 -> to call again frmSettlements because I get a acess violation

I don't think that will happen since you show the form modal (ShowModal)
How can I prevent calling the form again.
put a check and see if the form is of that class or not
procedure TfrmMain.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if not (Self is TfrmAlphaSearch) and (Key = VK_F3) then
   begin
      Application.CreateForm(TfrmAlphaSearch, frmAlphaSearch);
      try
         frmAlphaSearch.ShowModal();
      finally
         frmAlphaSearch.Free;
      end;
   end;
 
 
   if not (self is TfrmSettlements) and (Key = VK_F5) then
   begin
         Application.CreateForm(TfrmSettlements, frmSettlements);
         try
            frmSettlements.ShowModal();
         finally
            frmSettlements.Free;
         end;
    end;
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of reynaldio
reynaldio
Flag of Indonesia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial