Form object event cannot see inherited method
Summary of the problem:OnClick
Object event TForm
says it cannot find the method I specified; this method is defined in the superclass Form, which I expected it to inherit.
Here I define the base type (ie superclass) for the RAM Editor window, including the button and what the event should do OnClick
.
// File: RAM_Editor_Common.pas
type
TfrmBaseRamEditor = class(TForm)
btnMapfileLaden: TToolButton;
procedure MapfileLaden1Click(Sender: TObject);
// ....
procedure TfrmBaseRamEditor.Mapfileladen1Click(Sender: TObject);
begin
if not OpenDialog2.Execute then Exit;
StatusBar1.Panels[2].Text := OpenDialog2.FileName;
end;
This is where I define a subclass:
// File: RAM_Editor_SXcp.pas
TfrmRAM_Editor_SXcp = class(RAM_Editor_Common.TfrmBaseRamEditor)
Here, a button is used in the Form subclass and an event is set OnClick
for the method that was defined in the superclass:
// File: RAM_Editor_SXcp.dfm
object frmRAM_Editor_SXcp: TfrmRAM_Editor_SXcp
// ....
// ....
object btnMapfileLaden: TToolButton
Left = 75
Top = 0
Hint = 'Mapfile laden'
Caption = 'btnMapfileLaden'
OnClick = MapfileLaden1Click
ImageIndex = 5
ParentShowHint = False
ShowHint = False
end
But when I try to compile, I get the error:
"The method MapfileLaden1Click
referenced btnMapfileLaden.OnClick
does not exist. Are you sure you want to remove this link?"
Why can't he see the legacy method?
source to share
Your .dfm file is wrong, not:
object frmRAM_Editor_SXcp: TfrmRAM_Editor_SXcp
you need
inherited frmRAM_Editor_SXcp: TfrmRAM_Editor_SXcp
Similarly, instead of:
object btnMapfileLaden: TToolButton
you need
inherited btnMapfileLaden: TToolButton
I am assuming you are trying to inject a common base class into an existing hierarchy. You made the required changes to the .pas file, but could not make the appropriate changes to the .dfm file. The keyword inherited
in the .dfm file is required by inheriting the visual form.
source to share