Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Labels in ein Array? (https://www.delphipraxis.net/15469-labels-ein-array.html)

Splinter 29. Jan 2004 12:39


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 =)

Luckie 29. Jan 2004 12:45

Re: Labels in ein Array?
 
Irgendwelche Fehlermeldungen? Ohne das Kompiliert zu haben, sehe ich schon mindesten eine, wenn nicht sogar zwei.

gekmihesg 29. Jan 2004 12:46

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;

Gepard 29. Jan 2004 13:10

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:
end;
a[0] ist das 1. Feld
a[1] ist das 2. Feld
a[n-1] ist das letzte Feld im Array

Luckie 29. Jan 2004 13:12

Re: Labels in ein Array?
 
Und dabei
Delphi-Quellcode:
Array[Label1..label7]
dürfte sich auch Delphi weigern das zu kompilieren. Ein Objekt ist kein Ordinalwert.

Gepard 29. Jan 2004 13:13

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;

Nightshade 29. Jan 2004 13:21

Re: Labels in ein Array?
 
Zitat:

Zitat von Splinter
also wenn ich schreibe
...
mag er das auch nich
([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

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 ...

Splinter 29. Jan 2004 13:23

Re: Labels in ein Array?
 
Zitat:

Zitat von Gepard
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;

ich weiß schon im groben wie man nen arry umgeht aber halt nich wenn ich das mit nem label machen will

@gekmihesg


also wenn ich schreibe
Delphi-Quellcode:
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;
mag er das auch nich
([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?

Splinter 29. Jan 2004 13:32

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

Luckie 29. Jan 2004 13:37

Re: Labels in ein Array?
 
So irgendwie:
Delphi-Quellcode:
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;
Aber ich bekomme immer in den TLabel-Zeilen ein AV. :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:14 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz