What is the accepted way to use frames in Delphi?

后端 未结 4 750
轻奢々
轻奢々 2021-02-14 23:55

I was having my usual stroll around and bumped on some frames discussions.

I\'m mainly a Delphi hobbyist and not a professional, so I had to learn how to use TFrames my o

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 00:38

    The only problem with your approach is that you cannot add multiple instances of the same frame to a given form:

    Frame1 := TMyFrame.Create(Self);
    Frame1.Parent := Self;
    // ...
    Frame2 := TMyFrame.Create(Self); // bombs out with "a component with the name MyFrame already exists"
    

    The workaround for his is to assign a different name for each instance:

    Frame1 := TMyFrame.Create(Self)
    Frame1.Parent := Self;
    Frame1.Name := "FirstFrame";
    // ...
    Frame2 := TMyFrame.Create(Self); // works now, there is no name conflict
    

提交回复
热议问题