这是这个问题的后续: 在 Delphi 组件之间移动控件
在设计时,我将元素放入我的自定义 TPanel,但是当我将它们写入 DFM 时,我更改了它们的名称
procedure TPanelDialogo.VolcarFrameEnLista( );
var
i: integer;
Componente: TControl;
begin
// recorrer el frame y rescatar sus componentes
if FDesignPanel = nil then
exit;
for i := FDesignPanel.ControlCount - 1 downto 0 do
begin
Componente := FDesignPanel.Controls[i];
if Pos( self.Name + '_', Componente.Name ) = 0 then
begin
Componente.Name := self.Name + '_' + Componente.Name;
end;
if FListaComponentes.IndexOf(Componente) < 0 then
begin
FListaComponentes.Add( Componente );
end;
end;
end;
procedure TPanelDialogo.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
i: integer;
OwnedComponent: TComponent;
begin
if FDesignPanel <> nil then
VolcarFrameEnLista();
for i := 0 to self.FListaComponentes.Count - 1 do
begin
OwnedComponent := FListaComponentes.Items[i];
Proc(OwnedComponent);
end;
end;
在设计时,当我将标签放入自定义 TPanel 时,此标签会添加到 .pas 文件中的表单中:
写入 DFM 文件时,我重命名了标签,如前所述,因此 .pas 文件中的声明不再有效。
这是 .pas 文件
type
TForm1 = class(TForm)
CRTTESTPANEL: TGENPant;
PanelDialogo1: TPanelDialogo;
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
这就是 DFM
object Form1: TForm1
...
object CRTTESTPANEL: TGENPant
...
end
object PanelDialogo1: TPanelDialogo
...
object PanelDialogo1_Label1: TLabel
...
end
end
end
并且,单击“是”后,这些是 DFM 和 pas 文件:
TForm1 = class(TForm)
CRTTESTPANEL: TGENPant;
PanelDialogo1: TPanelDialogo;
private
{ Private declarations }
public
{ Public declarations }
end;
object Form1: TForm1
...
object CRTTESTPANEL: TGENPant
end
object PanelDialogo1: TPanelDialogo
...
object PanelDialogo1_Label1: TLabel
...
end
end
end
我想避免将标签声明写入 .pas 文件。我见过这个问题,但它与写入 DFM 文件有关,而不是 pas。
有没有办法做我想做的事?