Einzelnen Beitrag anzeigen

Tpercon

Registriert seit: 7. Jun 2002
638 Beiträge
 
Delphi 5 Professional
 
#13

Re: LabelPanel dringend gesucht!

  Alt 12. Feb 2004, 14:45
Ich würde mich mal nur in dem SetItems um die Labels kümmern:
Delphi-Quellcode:
constructor TMultiLinePanel.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  FLabels := TObjectList.Create(true);
  FItems := TStringList.Create;
end;

destructor TMultiLinePanel.Destroy;
begin
  if Assigned(FLabels) then begin
    FLabels.Free;
  end;
  if Assigned(FItems) then begin
    FItems.Free;
  end;
  inherited Destroy;
end;

procedure TMultiLinePanel.SetItems(Value: TStrings);
var
  aLabel : TLabel;
  i : integer;
begin
  FLabels.Clear;
  for i := 0 to Value.Count - 1 do begin;
    aLabel := TLabel.Create(nil);
    aLabel.Parent := self;
    aLabel.AutoSize := true;
    aLabel.Top := self.Height div (Value.Count + 1) * (i + 1);
    aLabel.Left := 8;
    aLabel.Caption := Value.Strings[i];
    FLabels.Add(aLabel);
  end;
  FItems.Text := Value.Text;
end;
So steuerst du das ganze:
Delphi-Quellcode:
  MyPanel := TMultiLinePanel.Create(self);
  MyPanel.Parent := self;
  ts := TStringList.Create;
  try
    ts.Add('bla');
    ts.Add('blubb');
    MyPanel.Items := ts;
  finally
    ts.Free;
  end;
  Mit Zitat antworten Zitat