2013-04-15 122 views
0

使用Firemonkey我有包含TPanel它會動態填充了一系列以下TDisplayItem對象的TVertScrollBox。德爾福XE3 Firemonkey自動調整大小/佈局問題

的問題是,TDisplayItem的正確等各個組件中的文本疊加不大小等

我就可以在處於滾動框的可視區域內的項目由得到解決這個問題零部件的尺寸,使該尺寸等。我已經試過清爽的容器和application.ProcessMessages得到的一切來調整大小以及各種對齊和經選擇,但無濟於事。

希望我已經錯過了在這一個關鍵因素,並沒有出土了Firemonkey限制!

乾杯,

Martin。

Constructor TDisplayItem.Create(owner : TComponent); 
begin 
    inherited Create(owner); 
    Align := TAlignLayout.alTop; 
    pnlLabels := TPanel.Create(nil); 
    pnlLabels.Align := TAlignLayout.alTop; 
    pnlLabels.Height := 50; 
    pnlLabels.Parent := self; 

    lblICAO := TLabel.Create(nil); 
    lblICAO.Parent := pnlLabels; 
    with lblICAO do 
    begin 
    text := 'ICAO'; 
    Height := 30; 
    Position.X := 10; 
    align := TAlignLayout.alTop; 
    TextAlign := TTextAlign.taCenter; 
    Font.Size := 18; 
    FontColor := $FF00D000 ; 
    Visible := False; 
    StyledSettings := [TStyledSetting.ssFamily];//, TStyledSetting.ssFontColor]; 
    end; 

    lblFrom := TLabel.Create(nil); 
    lblFrom.Parent := pnlLabels; 
    with lblFrom do 
    begin 
    text := 'From : '; 
    Height := 30; 
    Position.X := 10; 
    Position.y := 2; 
    width := 150; 
    FontColor := $FFFF0000 ; 
    StyledSettings := [TStyledSetting.ssFamily];//, TStyledSetting.ssFontColor]; 
    end; 

    lblTo := TLabel.Create(nil); 
     lblTo.Parent := pnlLabels; 
    with lblTo do 
    begin 
    text := 'To : '; 
    Height := 30; 
    Position.X := 170; 
    Position.y := 2; 
    width := 150; 
    FontColor := $FFFF0000 ; 
    StyledSettings := [TStyledSetting.ssFamily];//, TStyledSetting.ssFontColor]; 
    end; 



lblStatus := TLabel.Create(nil); 
    lblStatus.Parent := pnlLabels; 
    with lblStatus do 
    begin 
    text := 'Status : '; 
    Height := 30; 
    Position.X := 330; 
    Position.y := 2; 
    width := 100; 
    Font.Size := 10; 
    FontColor := $FFFF0000 ; 
    StyledSettings := [TStyledSetting.ssFamily];//, TStyledSetting.ssFontColor]; 
    end; 

    lblNonGeog := TLabel.Create(nil); 
    with lblNonGeog do 
    begin 
    text := 'Non-Geog : '; 
    Height := 30; 
    Position.X := 440; 
    Position.y := 2; 
    width := 150; 
    Font.Size := 10; 
    FontColor := $FFFF0000 ; 
    StyledSettings := [TStyledSetting.ssFamily];//, TStyledSetting.ssFontColor]; 
    end; 
    lblNonGeog.Parent := pnlLabels; 

    memItem := TLabel.Create(nil); 
    memItem.Parent := self; 
    with memItemE do 
    begin 
    Align := TAlignLayout.alTop; 
    DisableFocusEffect := False; 
    AutoSize := True; 
    WordWrap := True; 
    end; 
+0

你在任何時候(無論是在組件或創建它們時)設置你的TDisplayItems的大小?什麼是TDisplayItem的父項? –

+0

父設置爲可視化包含它們的TPanel。大小通過迭代獲取每個父元素的高度並將每個父元素的高度設置爲子控件高度的總和來設置。 –

+0

對不起,我的意思是父類,而不是父母控制。如果課程是TPanel,則可以將每個標籤製作爲直接孩子並避免使用額外的面板。那麼你控制身高將成爲Position.Y + Height最高的孩子。我會建議在顯示項目類中這樣做。 –

回答

0

好的,終於解決了。我正確地認爲這是一個繪圖問題 - 當一個標籤的文本被改變時,需要一個label.dopaint。然後更新標籤的高度,即使它不在顯示區域。通過總結兒童組件的高度,可以正確設置TPanel的高度。