![]() |
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; |
Re: Labels in ein Array?
FindComponent ist in der Unit Classes enthalten.
|
Re: Labels in ein Array?
muss ich dann irgendwas davorschreiben?
classes.findcomponent oder sowas? |
Re: Labels in ein Array?
Unter
Code:
sollte u.a. dies zu finden sein:
interface
uses classes |
Re: Labels in ein Array?
ist es auch und da steht finccomponent auch drin aber er sagt trotzdem
[Error] Unit1.pas(202): Undeclared identifier: 'findcomponent' |
Re: Labels in ein Array?
Dann poste mal bitte deinen entsprechenden Code.
|
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; das was nightsahde schon gepostet hat |
Re: Labels in ein Array?
Ich habe das jetzt mal getestet und so geht's definitiv:
Delphi-Quellcode:
Weiß nicht, was du sonst noch anders hast?
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i: Integer; procedure tagsichtbar(Mytag: TLabel); begin if Mytag.Visible then Form1.Memo2.Lines.Add(Mytag.name); end; begin for i := 1 to 4 do begin tagsichtbar(FindComponent('Label'+inttostr(i)) as TLabel); end; end; end. |
Re: Labels in ein Array?
das geht bei mir auch wenn ich das in nen neues formular schreibe aber wnn ich in das alte reinschreibe dann sagt er
[Error] Unit1.pas(202): Undeclared identifier: 'findcomponent' ich versteht das nich °_^ |
Re: Labels in ein Array?
so hab ma gestestet wenn ich in mein formular nen button reinmache und das reinschreibe dann meckert er nich
aber bei der prozedur oben schon WIESO? 8[ |
Re: Labels in ein Array?
Dann poste doch mal den kompletten Interface Teil (die Komponentenaufzählung kannst du ja was kürzen) und den relevanten Implementation Teil.
|
Re: Labels in ein Array?
Delphi-Quellcode:
die relevanten labels und so is alled definiert (hab ich nur gekürzt)(hier kann der fehler nich liegen weil wenn ich die prozedur rausnehme läuft alles ohne prob)
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, TabNotBk, PieEffekt, PieComboBox, inifiles; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; ..... ListBox1: TListBox; Memo4: TMemo; Edit2: TEdit; procedure Edit1Change(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Label1Click(Sender: TObject); .... procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } SetPath :string; procedure Notizalter; public { Public declarations } end; const Startjahr = 2004; var memo, s: String; Form1: TForm1; EingabeJahr: Integer = 2004; ersterTagJ, ersterTagM: Integer; code : Integer; searchRec: TSearchRec; implementation {$R *.dfm} 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; [edit=Luckie]Delphi-Tags ergänzt. Mfg, Luckie[/edit] |
Re: Labels in ein Array?
Dann deklarier mal deine Procedure:
Delphi-Quellcode:
und die Definition sollte wie folgt aussehen:
public
{ Public declarations } procedure sichtbareTageeins; end;
Delphi-Quellcode:
Wie schauts damit aus?
procedure TForm1.sichtbareTageeins;
var i: Integer; ... |
Re: Labels in ein Array?
yuhuhuuh
klappt :D thx =) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:18 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