![]() |
Labels in ein Array?
Hi
ich habe in meinem projekt paar labels die je nachdem ob sie sichtbar sind oder nicht in ein memo hinzugefügt werden sollen(für effekte -PieTools-) ich könnte auch 7x tagsichtbar(Label1) tagsichtbar(Label2)... usw schreiben aber es müsste doch auch irgendwie mit nem array gehen. ich hab dann das hier gemacht aber das mag delphi anscheinend irgendwie nich...
Delphi-Quellcode:
procedure sichtbareTageeins;
var a: Array[Label1..label7] of Tlabel; i: Integer; Procedure tagsichtbar(tag: Tlabel;); begin If Unit1.Form1.tag.Visible = true Then Unit1.Form1.Memo2.lines.Add(tag.name); end; begin For i := 1 to 7 DO tagsichtbar(a[i]) end; kann ich in ein array keine labels reinschreiben oder wo liegt mein fehler? sry wenn ich mit meinem newbgeschwätz nerve aber hab grad erst angefangen mit delphi und weiß manchmal einfach nicht was ich falsch mache =) |
Re: Labels in ein Array?
Irgendwelche Fehlermeldungen? Ohne das Kompiliert zu haben, sehe ich schon mindesten eine, wenn nicht sogar zwei.
|
Re: Labels in ein Array?
Delphi-Quellcode:
var i:integer;
begin for i:=1 do 7 do tagsichtbar((findocomponent('Label'+inttostr(i)) as TLabel)); end; |
Re: Labels in ein Array?
wenn du ein Array nimmst dann achte darauf wie die Felder angesprochen werden
wenn das Array n Felder hat muss der Code in etwa so aussehen (nur ein einfaches Beispiel)
Delphi-Quellcode:
var
Delphi-Quellcode:
i, x: Integer
Delphi-Quellcode:
begin
Delphi-Quellcode:
for i := 1 to n do
Delphi-Quellcode:
x := a[i-1]
Delphi-Quellcode:
a[0] ist das 1. Feld
end;
a[1] ist das 2. Feld a[n-1] ist das letzte Feld im Array |
Re: Labels in ein Array?
Und dabei
Delphi-Quellcode:
dürfte sich auch Delphi weigern das zu kompilieren. Ein Objekt ist kein Ordinalwert.
Array[Label1..label7]
|
Re: Labels in ein Array?
Sorry sieht sehr blöd aus :duck:
Delphi-Quellcode:
var
i, x: Integer begin for i := 1 to n do x := a[i-1] end; |
Re: Labels in ein Array?
Zitat:
Delphi-Quellcode:
procedure sichtbareTageeins;
var i: Integer; Procedure tagsichtbar(Mytag: Tlabel); begin If Mytag.Visible Then Form1.Memo2.lines.Add(Mytag.name); end; begin for i := 1 to 7 do tagsichtbar((findcomponent('Label'+inttostr(i)) as TLabel)); end; Mag daran liegen, das Form1.tag eine vorhandene Variable ist. Versuchs mal so wie oben ... |
Re: Labels in ein Array?
Zitat:
@gekmihesg also wenn ich schreibe
Delphi-Quellcode:
mag er das auch nich
procedure sichtbareTageeins;
var i: Integer; Procedure tagsichtbar(tag: Tlabel); begin If Unit1.Form1.tag.Visible = true Then Unit1.Form1.Memo2.lines.Add(tag.name); end; begin for i := 1 to 7 do tagsichtbar((findocomponent('Label'+inttostr(i)) as TLabel)); end; ([Error] Unit1.pas(195): Record, object or class type required [Error] Unit1.pas(200): For loop control variable must be simple local variable [Error] Unit1.pas(201): Undeclared identifier: 'findocomponent' [Error] Unit1.pas(201): Operator not applicable to this operand type) usw luckie hast vielleicht auch ne idee wie man das umsetzen kann? |
Re: Labels in ein Array?
Delphi-Quellcode:
procedure sichtbareTageeins;
var i: Integer; Procedure tagsichtbar(Mytag: Tlabel); begin If Mytag.Visible Then Form1.Memo2.lines.Add(Mytag.name); end; begin for i := 1 to 7 do tagsichtbar((findcomponent('Label'+inttostr(i)) as TLabel)); end; Mag daran liegen, das Form1.tag eine vorhandene Variable ist. Versuchs mal so wie oben ...[/quote] er hat komischerweise immer probleme mit der function findcomponent wieso findet er die nich?? aber wenn ichs so mache wie du sind nur noch 2 fehlermeldungen über :D : [Error] Unit1.pas(203): Undeclared identifier: 'findcomponent' [Error] Unit1.pas(203): Operator not applicable to this operand type |
Re: Labels in ein Array?
So irgendwie:
Delphi-Quellcode:
Aber ich bekomme immer in den TLabel-Zeilen ein AV. :gruebel:
type
TForm1 = class(TForm) CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var Loop: Cardinal; begin for Loop := 1 to 3 do begin with TCheckBox(FindComponent('Checkbox'+IntToStr(Loop))) do begin if Checked then TLabel(FindComponent('Label'+IntTostr(Loop))).Visible := True else TLabel(FindComponent('Label'+IntTostr(Loop))).Visible := False; end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:15 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz