This is a follow up of this question: Moving controls between Delphi components
In design time I put elements into my custom TPanel but when I write them to the DFM I change their names
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;
In design time, when I put a label into the custom TPanel this label is added to the form in the .pas file:
When writing to the DFM file I rename the label, as seen before so the declaration in the .pas file is no longer valid.
This is the .pas file
type
TForm1 = class(TForm)
CRTTESTPANEL: TGENPant;
PanelDialogo1: TPanelDialogo;
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
And this is the DFM
object Form1: TForm1
...
object CRTTESTPANEL: TGENPant
...
end
object PanelDialogo1: TPanelDialogo
...
object PanelDialogo1_Label1: TLabel
...
end
end
end
And, after clicking "Yes" these are the DFM and pas files:
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
I'd like to avoid writing the label declaration to the .pas file. I've seen this question but it relates to writing to the DFM file, not the pas.
Is there a way to do what I want?