1
Follow the code below:
type
TfObject = class(TForm)
private
procedure FormShow(Sender : TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
constructor Create(AOwner : TComponent); override;
{ Public declarations }
end;
Create code:
constructor TfObject.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
Position := TPosition.poScreenCenter;
WindowState := wsNormal;
KeyPreview := true;
AlphaBlend := true;
AlphaBlendValue := 0;
BorderStyle := bsSizeable;
OnShow := FormShow;
OnKeyDown := FormKeyDown;
OnClose := FormClose;
end;
The problem is this, according to what I know related to Delphi with O.O.O., I could use this way to inherit the methods contained in the Father class, but when I do so, I cannot use the inherited in the daughter class, which is in this case the form that is inheriting from TfObject.
I found that by doing the class this way, I can normally use the form methods, but when I put to the form methods (OnShow, OnClose, OnKeyDown) to receive his proper methods, he behaves as if the daughter class were doing this.
Now my question...
How I do for my class TForm assign your form methods and I just inherit them when I implement a method (OnShow, OnClose, OnKeyDown)?
Example:
procedure TForm1.FormShow(sender : TObject);
begin
//faz algo
inherited;
//faz algo
end;
Well, I implemented it earlier this way, but every time I declare the Son Form inherited from the Father, I can use the
DoShowUsually, but theFormShowof the child form there is noinheirted, due to when creating the same, it assigns to the method that is running now.– Ramon Ruan
Exactly, it turns out that the Formshow is a method declared in the local class (daughter), she is not replacing that of the father. Procedure Formshow(Sender : Tobject); No virtual and no override. This is because it is the method triggered by the event assigned only locally, in this case it has no way to use inherited.
– Luciano Trez