开发者

Delphi 7 inheritance

Have 6 forms, 1 Base and 5 inherited.The Base has the following snippet:

procedure TMechan.Open1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Form1.Memo1.Lines.LoadFromFile(OpenDialog1.FileName );
  CopyCylMemoToRecord;
  ShowMechanicalValues;
end;

Since this snippet is in the Base it's also inherited by 5 others. P开发者_如何学Croblem is: When executing OpenDialog the Base is overwritten instead of the inherited form. HELP


I'm not exactly sure what you mean with the Base is overwritten but your use of Form1 in your code should probably be changed to Self.

Form1 is a global reference to one instance of (probably) your Base form. You could create a zillion TMechan form instances where each and every Open1Click would be changing a property of that One Form.

I assume the forms are autocreated. While that is easy to get going, I would strongly advice you to not autocreate each and every form and to remove all global references to forms (like this form1) where possible.

The only form that should get autocreated is your main form. All other forms should be created when needed, something like myform := TMechan.Create(AOwner);

procedure TMechan.Open1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Self.Memo1.Lines.LoadFromFile(OpenDialog1.FileName );
  CopyCylMemoToRecord;
  ShowMechanicalValues;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜