J'essaie de convertir un ensemble de formulaires créés avec un outil personnalisé en formulaires Delphi. J'essaie d'ajouter tous les composants nécessaires à l'exécution, puis utiliser WriteComponentResFile pour créer le fichier DFM.WriteComponentResFile n'inclut pas les composants ajoutés dynamiquement à TTabSheet
Tous mes tests initiaux ont semblé bons jusqu'à ce que j'ai essayé d'ajouter un TPageControl et TabSheets. Les formulaires actuels peuvent avoir plusieurs pages, donc j'allais refléter cela en utilisant le PageControl. Le problème est que tous les composants que j'ajoute à une TabSheet ne sont pas diffusés vers le DFM. Il semble bon si je montre le formulaire mais quelque chose manque pour WriteComponentResFile.
Je suis en train d'écrire un fichier pas correspondant afin que je puisse l'ouvrir dans l'EDI une fois terminé. L'objectif est de s'éloigner du concepteur de formulaire personnalisé et de commencer à utiliser l'IDE Delphi pour notre concepteur de formulaires.
Voici quelques exemples de code montrant comment je crée les composants:
procedure WriteFormAsDFM(OutputFileName: string);
var
PageIndex: integer;
PageCount: Integer;
OutputForm: TForm;
Pages: TPageControl;
NewPage: TTabSheet;
NewLabel: TLabel;
begin
OutputForm := TForm.Create(nil);
OutputForm.Name := ChangeFileExt(ExtractFileName(OutputFileName), '');
OutputForm.Caption := OutputForm.Name;
OutputForm.Height := 300;
OutputForm.Width := 300;
Pages := TPageControl.Create(OutputForm);
Pages.Parent := OutputForm;
Pages.Top := 50;
Pages.Left := 0;
Pages.Height := 200;
Pages.Width := 200;
NewLabel := TLabel.Create(OutputForm);
NewLabel.Parent := OutputForm;
NewLabel.Caption := 'Label on Form';
//write pages
PageCount := 2;
for PageIndex := 0 to PageCount - 1 do
begin
NewPage := TTabSheet.Create(Pages);
NewPage.Parent := Pages;
NewPage.PageControl := Pages;
NewPage.Caption := 'Page ' + IntToStr(PageIndex);
NewPage.Name := 'tsPage' + IntToStr(PageIndex);
NewLabel := TLabel.Create(NewPage);
NewLabel.Parent := NewPage;
NewLabel.Caption := 'Label on ' + NewPage.Caption;
end;
WriteComponentResFile(OutputFileName, OutputForm);
//WritePasFile(OutputFileName, OutputForm);
OutputForm.ShowModal;
FreeAndNil(OutputForm);
end;
et est le fichier DFM ici qui est sortie. Vous pouvez voir que l'étiquette sur le formulaire est créée mais pas les étiquettes ajoutées aux feuilles de tabulation.
object Form123: TForm
Left = 69
Top = 69
Caption = 'Form123'
ClientHeight = 264
ClientWidth = 284
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object TLabel
Left = 0
Top = 0
Width = 67
Height = 13
Caption = 'Label on Form'
end
object TPageControl
Left = 0
Top = 50
Width = 200
Height = 200
ActivePage = tsPage0.Owner
TabOrder = 0
object tsPage0: TTabSheet
Caption = 'Page 0'
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
end
object tsPage1: TTabSheet
Caption = 'Page 1'
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
end
end
end
Merci qui s'en est occupé. –