Einzelnen Beitrag anzeigen

Benutzerbild von Daniel Schuhmann
Daniel Schuhmann

Registriert seit: 16. Jul 2005
Ort: München
391 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: label erstellen --> Name?

  Alt 10. Jan 2006, 13:57
Mal ne ganz andere Frage... warum nicht einfach die Namen zur Laufzeit vergeben? Folgendes funktioniert bei mir zumindest:

Delphi-Quellcode:
type
  // [...]
  private
    procedure SetMyLabelCaption(LabelName, Caption: String);
  end;

var
  // [...]
  Anzahl: Integer;

implementation

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  MyLabel: TLabel;
begin
  MyLabel := TLabel.Create(Form1);

  inc(anzahl);
  with MyLabel do
  begin
    Caption := 'test';
    Top := 100+Anzahl*20;
    Left := 150;
    Parent := Form1;
    Name := 'Label'+IntToStr(Anzahl);
  end;
end;

procedure TForm1.SetMyLabelCaption(LabelName, Caption: String);
begin
  TLabel(FindComponent(LabelName)).Caption := Caption;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SetMyLabelCaption('Label2', 'Hallo');
end;
Daniel Schuhmann
  Mit Zitat antworten Zitat