Domanda

Using Firemonkey I have a TVertScrollBox which contains a TPanel which gets dynamically populated with a number of the following TDisplayItem objects.

The problem is that the TDisplayItem’s don’t size properly so the text on the various components is superimposed etc.

I can fix this on the items that are in the visible area of the scrollbox by by getting the sizes of the component parts and making the containers that size etc. I’ve tried refreshing and application.ProcessMessages to get everything to resize as well as various alignment and warp options but to no avail.

Hopefully I’ve missed a key factor in this and haven’t unearthed a Firemonkey limitation!

Cheers,

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;
È stato utile?

Soluzione

OK, finally solved it. I was on the right lines thinking it was a drawing issue - when the text of one of the labels was changed a label.dopaint was needed. This then updated the height of the label even if it was not in the display area. The paraent TPanel could then have it's height set correctly by summing the heights of the child components.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top