Autor Beitrag
Kay E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: Fr 19.11.10 22:34 
Hallo!

Am besten zuerst einmal der Code (Ausschnitt):
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
type
  TStatistik= record
    Feld:TLabel;
    AnzahlK:Integer;
    AnzahlT:Integer;
  end;

  TStatistikpanelKlein=class(TPanel)
  private
    L00:TStatistik;
    L01:TStatistik;
    L02:TStatistik;
    L10:TStatistik;
    L11:TStatistik;
    L12:TStatistik;
    L20:TStatistik;
    L21:TStatistik;
    L22:TStatistik;
    Erzeugt:boolean;
  end;

var
  StatistikpanelKlein:TstatistikpanelKlein;

procedure StatistikBauen(Owner:TComponent);


implementation

procedure StatistikBauen(Owner:Tcomponent; Wiesetyp:TWiesetyp);
var
i,j:integer;
begin
  StatistikPanelKlein:=TStatistikpanelKlein.Create(Owner);
  StatistikPanelKlein.Parent:=Form1;
  StatistikpanelKlein.Left:=25;
  StatistikpanelKlein.Top:=25;

  StatistikpanelKlein.L00.Feld:=TLabel.Create(StatistikpanelKlein);
  StatistikpanelKlein.L00.Feld.Parent:=StatistikpanelKlein;
  StatistikpanelKlein.L00.Feld.Caption:='Testerle';

  i:=0; j:=0;
  with StatistikpanelKlein do begin
    TStatistik(FindComponent('l'+inttostr(i)+inttostr(j)).Feld.caption:='Hat funktioniert';
    invalidate;
  end;
end;


Ich baue hier einen Record, in dem ein TLabel ist, welches ich nachher 9 mal (als Raster) in dem Panel als Container unterbringen will. Mit jedem Label sollen noch weitere Informationen gespeichert werden, deswegen das Record.
Damit ich dann nicht alle 9 Labels umständlich manuell ausrichten, benennen, Parent zuweisen, etc muss, würd ich das gern in ne Schleife verpacken und würde dafür die FindComponent-Funktion nutzen.
Bei dem Code oben wird mir allerdings der Fehler ausgegeben "TComponent" does not contain a member named "Feld" und undeclared identifier "caption".
Ich entdecke von der Logik her keinen Fehler in meinem Code, aber vlt. könnt ihr mir ja helfen.
Wie kann ich meine Labelkomponente in den Records elegant ansteuern?


Danke für eure Hilfe!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 19.11.10 23:17 
Ich markiere dir mal deine zusammengehörigen Klammern...
ausblenden Delphi-Quelltext
1:
    TStatistik(FindComponent('l'+inttostr(i)+inttostr(j)).Feld.caption:='Hat funktioniert';					
Da Delphi die ja auch hervorhebt, die zusammengehören, sieht man das eigentlich ganz gut. :gruebel:


Zuletzt bearbeitet von jaenicke am Fr 19.11.10 23:18, insgesamt 1-mal bearbeitet
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Fr 19.11.10 23:18 
Also direkt auf die Frage hab ich auch keine präzise Antwort (nur Vermutungen).

ABER:

Warum so kompliziert?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
  TStatistikpanelKlein=class(TPanel)
  private
    L: array [0..2of array [0..2of TStatistik;
    Erzeugt:boolean;
  end;

var
  StatistikpanelKlein:TstatistikpanelKlein;

procedure StatistikBauen(Owner:TComponent);


implementation

procedure StatistikBauen(Owner:Tcomponent; Wiesetyp:TWiesetyp);
var
i,j:integer;
begin
  StatistikPanelKlein:=TStatistikpanelKlein.Create(Owner);
  StatistikPanelKlein.Parent:=Form1;
  StatistikpanelKlein.Left:=25;
  StatistikpanelKlein.Top:=25;

  StatistikpanelKlein.L00.Feld:=TLabel.Create(StatistikpanelKlein);
  StatistikpanelKlein.L00.Feld.Parent:=StatistikpanelKlein;
  StatistikpanelKlein.L00.Feld.Caption:='Testerle';

  i:=0; j:=0;
  StatistikpanelKlein.L[i,j].Feld.caption:='Hat funktioniert';
end;


//Edit:
Das ist zudem auch noch deutlich schneller als FindComponent.

Achtung: Nicht vergessen, die Labels zu createn, bevor du was reinschreiben willst

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
Kay E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: So 21.11.10 14:08 
Oh mann, wie kann man nur so auf dem Schlauch stehen? *g*
Die Lösung mit den Arrays ist natürlich naheliegend - Danke!
der organist
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: So 21.11.10 15:25 
user profile iconXion hat folgendes geschrieben Zum zitierten Posting springen:
[...]
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
[...]

procedure StatistikBauen(Owner:Tcomponent; Wiesetyp:TWiesetyp);
var
i,j:integer;
begin
  [...]
  i:=0; j:=0;
  StatistikpanelKlein.L[i,j].Feld.caption:='Hat funktioniert';

end;
[...]



Reicht euch das hier nicht aus? xD

ausblenden Delphi-Quelltext
1:
StatistikpanelKlein.L[0,0].Feld.caption:='Hat funktioniert';					

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
Kay E. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 118



BeitragVerfasst: So 21.11.10 15:59 
In diesem speziellen Fall schon, aber wenn du meinen Text unter dem Code gelesen hättest:

Zitat:
Damit ich dann nicht alle 9 Labels umständlich manuell ausrichten, benennen, Parent zuweisen, etc muss, würd ich das gern in ne Schleife verpacken


und genau dafür sind die Laufvariablen gedacht. Sozusagen als Dummys in einer Trockenübung eingesetzt.
der organist
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 467
Erhaltene Danke: 17

WIN 7
NQC, Basic, Delphi 2010
BeitragVerfasst: So 21.11.10 22:53 
Da war aber keine Schleife mehr...... ich würd mal sagen, dass jemand anders deinen Text nich gelesen hat...

_________________
»Gedanken sind mächtiger als Waffen. Wir erlauben es unseren Bürgern nicht, Waffen zu führen - warum sollten wir es ihnen erlauben, selbständig zu denken?« Josef Stalin
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Mo 22.11.10 08:43 
Ähm...auch im Originalcode war es keine Schleife ;)

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)