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.
henryreynoldsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
in frmMain you are using KeyPreview ?
in frmCapture set it off

or provide a little more code so we can see what you ment ...
MerijnBSr. Software EngineerCommented:
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

henryreynoldsAuthor Commented:
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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

MerijnBSr. Software EngineerCommented:
> 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)
henryreynoldsAuthor Commented:
How can I prevent calling the form again.
Geert GOracle dbaCommented:
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

reynaldioCommented:
- why don't you set FormKeyUp virtual in frmMain

procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;


- and override that procedure in frmSettlements


procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); override;
begin
    if Key = VK_F3 then Key := 0;
    inherited FormKeyUp(Sender, Key, Shift);
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.