henryreynolds
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.
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.
Like Geert suggests, set frmMain.KeyPreview to true
in frmMain, change the Key to 0 after you've handled it:
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;
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(Tfr mAlphaSear ch, frmAlphaSearch);
try
frmAlphaSearch.ShowModal() ;
finally
frmAlphaSearch.Free;
end;
end;
if Key = VK_F5 then
begin
Application.CreateForm(Tfr mSettlemen ts, 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
procedure TfrmMain.FormKeyUp(Sender:
Shift: TShiftState);
begin
if Key = VK_F3 then
begin
Application.CreateForm(Tfr
try
frmAlphaSearch.ShowModal()
finally
frmAlphaSearch.Free;
end;
end;
if Key = VK_F5 then
begin
Application.CreateForm(Tfr
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)
I don't think that will happen since you show the form modal (ShowModal)
ASKER
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in frmCapture set it off
or provide a little more code so we can see what you ment ...