?
Solved

Delphi form overriding form inheritance

Posted on 2009-02-12
7
Medium Priority
?
824 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:henryreynolds
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23622409
in frmMain you are using KeyPreview ?
in frmCapture set it off

or provide a little more code so we can see what you ment ...
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 23622656
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

0
 

Author Comment

by:henryreynolds
ID: 23623785
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:MerijnB
ID: 23623806
> 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)
0
 

Author Comment

by:henryreynolds
ID: 23625754
How can I prevent calling the form again.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23630211
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

0
 
LVL 2

Accepted Solution

by:
reynaldio earned 500 total points
ID: 23640085
- 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;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question