在运行时创建 Tframe:
是否可以创建运行时框架并添加现有面板,例如将面板的父级设置为框架?添加后,复制框架并使用它?
就像:
f:= Tframe. create(..)
...
panel3.parent = f; //where panel3 has many controls.
然后复制 f?有可能吗?如何?或任何其他建议? e
is it posible to create runtime frame and add existing panels like setting the parent of panel to the frame? and when it added, dulplicate the frame and use it?
like:
f:= Tframe. create(..)
...
panel3.parent = f; //where panel3 has many controls.
then duplicate the f? was it posible? how? or any other suggerstion?
e
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你不会通过重复来解决这个问题。你需要的是这样的函数:
I don't think you would solve this by duplicating. What you need is a function like this:
您需要记住,所有控件都有一个父控件和一个所有者。所有者可能是
nil
,但随后您需要通过代码释放这些控件,因此大多数控件由其他某个组件拥有。因此,如果所有者被摧毁,面板也会被摧毁。如果面板是在设计时创建的,那么它就属于它所在的表单!
破坏那个形态就会破坏面板!
但是,如果您在运行时创建面板并将
Application
设置为所有者而不是表单,则它们可以在多个表单和框架上移动。但这是一个好的设计模式吗?我不知道你想做什么,但这可能是个坏主意!
一般来说,在设计时就用面板设计整个框架会更实用。然后添加一些代码,允许通过从另一个面板或控件复制数据来创建框架。这将是一个更好的设计模式......
You need to remember that all controls have a parent and an owner. Owners could be
nil
but then you need to free those controls through code, so most controls are owned by some other component.Thus, if the owner gets destroyed, the panel would be destroyed too. And if the panel was created in design-time then it's owned by the form that it's on!
Destroying that form would destroy the panel!
But if you create the panels in runtime and set
Application
as owner instead of a form, they could be moved over multiple forms and frames.But is it a good design pattern? I don't know what you're trying to do but it's likely a bad idea!
In general, it would be more practical to design the whole frame with panels in design-time. Then add some code that would allow the frame to be created by copying data from another panel or control. That would be a better design pattern...
您必须使用与创建第一个框架 (FRAME1) 相同的代码来创建新框架 (FRAME2);之后,您必须在 FRAME2 上创建 FRAME1 内包含(在运行时创建)的所有组件。
为此,请使用:
您可以尝试第二种选择;使用 TMemoryStream (SaveComponent) 保存 FRAME1,然后创建新的 Frame 并检索 Stream 上保存的信息(我没有测试此选项)。
问候。
You must create the new frame (FRAME2) with the same code that you have used to create the first (FRAME1); And later, you must create all the component included (created on runtime) inside FRAME1 on FRAME2.
For to this, use:
You can try a second alternative; Save the FRAME1 using a TMemoryStream (SaveComponent) and later create the new Frame and retrieve the saved information on Stream (I don't have test this option).
Regards.