Nic*_*las 2 forms delphi frame
我一直致力于Delphi 2009中的一个程序.它与物化的"Mimics"程序非常相似,您可以在其中创建和操作3D网格.有4个具有不同方面的面板用于查看3D对象(XY,YZ,XZ和3D透视图).每个面板都是我为查看3D对象而制作的自定义框架的实例.然后将4个面板装载到具有按钮和其他部件的表格上.
我遇到的一个问题是框架必须访问它们所在表单的子例程.EG如果我在其中一个框架中更改了某些关于网格的内容,则应更新(刷新)所有框架,这是父窗体中可用的过程.但是要在父表单上调用过程,我必须在3D框架的implementation uses子句中包含父表单的单元文件.这没关系,这一般都没有任何问题.问题是我不能使用父表单继承.如果我从父窗体创建一个继承的类,单元名称和窗体名称会更改,然后我必须更改3D框架以引用此新更改的窗体.
这真的是我的问题的关键.我不知道如何从子框架引用父窗体的属性,而不明确说明窗体的名称.我希望能够重用和扩展父表单,但我不知道如何在不改变表单使用的3D帧的情况下实现它.
任何帮助将不胜感激.谢谢.
Mas*_*ler 10
所以你有一个自包含的组件(一个框架),它必须能够从它所放置的表单中调用代码,而没有对表单本身的编译时知识?听起来很像TButton,当你点击它时,它不知道如何处理它的形式,并且解决方案是相同的:使用事件处理程序.将OnChangeMesh(或类似的东西)事件属性添加到您的框架,并让您的表单在创建框架时分配适当的方法.
另一个选项可能是定义父表单实现的接口.它应该具有您想要从子框架访问的所有属性和方法,例如:
ImyFormInterface=interface
['{08BD9B3C-C48E-47B7-AE67-279277C7E024}']
function GetValue1: integer;
function GetValue2: integer;
procedure SetValue1(val: integer);
procedure SetValue2(val: integer);
procedure SomeMethod;
function GetSomeValue: integer;
property Value1: integer read GetValue1 write SetValue1;
property Value2: integer read GetValue2 write SetValue2;
end;
Run Code Online (Sandbox Code Playgroud)
然后让你的主表单实现该接口:
TForm1 = class(TForm, ImyFormInterface)
private
{ Private declarations }
public
// Implement ImyFormInterface
function GetValue1: integer;
function GetValue2: integer;
procedure SetValue1(val: integer);
procedure SetValue2(val: integer);
procedure SomeMethod;
function GetSomeValue: integer;
public
{ Public declarations }
end;
Run Code Online (Sandbox Code Playgroud)
然后在你的框架中你可以使用类似的东西:
procedure Tframe1.Button1Click(Sender: TObject);
var pform: TcustomForm;
i: ImyFormInterface;
begin
pform:=GetParentForm(self);
if (pform.GetInterface(ImyFormInterface, i)) then
begin
i.SomeMethod;
i.Value1:=i.Value1+10;
Self.SomeProperty:=i.GetSomeValue;
end;
end;
Run Code Online (Sandbox Code Playgroud)
现在,如果你从父表单继承它,它仍然可以工作,因为你仍然会得到接口.此外,您可以将您的帧放在一个全新的表单上,只要该新表单实现该接口,它也将在那里工作.
| 归档时间: |
|
| 查看次数: |
3108 次 |
| 最近记录: |