的組件我試圖將一組使用自定義工具創建的窗體轉換爲Delphi窗體。我試圖在運行時添加所有必要的組件,然後使用WriteComponentResFile創建DFM文件。WriteComponentResFile不包括動態添加到TTabSheet
我嘗試添加TPageControl和TabSheets之前,所有的初始測試看起來都不錯。當前表單可以有多個頁面,所以我將使用PageControl來對此進行鏡像。問題是我添加到TabSheet的任何組件都沒有流出到DFM。它看起來不錯,如果我顯示窗體,但WriteComponentResFile缺少的東西。
我正在寫出一個相應的pas文件,所以我可以在IDE中完成後打開它。目標是遠離自定義表單設計器,並開始爲我們的表單設計器使用Delphi IDE。
這裏是展示我如何正在創建的組件一些示例代碼:
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;
這裏是DFM文件輸出。您可以看到表單上的標籤已創建,但未添加到TabSheets中的標籤。
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
謝謝你照顧它。 – 2009-12-30 18:01:43