Problem summary: The OnClick
event of a TForm
object says that it can't find the method I specify; this method is defined in the Form's superclass, which I expected it to be inherited.
Here I define the base type (i.e. superclass) for the "RAM Editor" window, including a button and what its OnClick
event should do.
// 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;
Here I define the sub-class:
// File: RAM_Editor_SXcp.pas
TfrmRAM_Editor_SXcp = class(RAM_Editor_Common.TfrmBaseRamEditor)
Here the sub-class's Form makes use of the button and sets the OnClick
event to the method that was defined in the super-class:
// 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 attempt to compile I get the error:
"The MapfileLaden1Click
method referenced by btnMapfileLaden.OnClick
does not exist. Remove this reference?"
Why can it not see the inherited method?
Your .dfm file is incorrect instead of:
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 guess you are trying to inject a common base class into an existing hierarchy. You've made the changes needed in the .pas file, but failed to make the corresponding changes needed in the .dfm file. The inherited
keyword in the .dfm file is required by visual form inheritance.