Autor Beitrag
Christoph Englmann
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Di 07.03.06 12:23 
hallo,

habe eine scrollbox, in der es verschiedene Komponenten gibt.

Nun möchte ich alle Komponenten in der Scrollbox durchlaufen und wenn es sich um eine TEdit Komponente handelt und diese dann (2.if Bedingung) einen bestimmte Tag hat, soll z.B. ReadOnly auf false gesetzt werden.

hier der code
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:
procedure Aktivieren_Deaktivieren_Textfelder(Parent :TWinControl);
var
  i :integer;
  test :Tcontrol;
begin

  for i := 0 to Parent.ControlCount-1 do
  begin
    //TEdit
    test := Parent.Controls[i];
    if Parent.Controls[i] is TEdit then
    begin
      if Parent.Tag = Aktor then
      begin
        (Parent.Controls[i] as TEdit).Color := clblack;
        (Parent.Controls[i] as TEdit).ReadOnly := false;
      end
      else
      begin
        (Parent.Controls[i] as TEdit).Color := clgray;
        (Parent.Controls[i] as TEdit).ReadOnly := true;
      end;
    end;

  end;

end;



Problem ist, dass mir das Programm nie in die Erste If-Bedingung einspringt, sprich die Bedingung
if Parent.Controls[i] is TEdit then
wird nie erfüllt, obwohl sehr viele Edit Komponenten in der ScrollBox vorhanden sind.


danke
christoph



Moderiert von user profile iconChristian S.: Schließenden Delphi-Tag an korrekte Position verschoben
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Di 07.03.06 12:29 
Ja und wie äußert sich der Fehler? Werden die Schleifen garnicht durchlaufen oder falshce Elemente deaktiviert oder...?

Sieht auf den ersten Blick doch gut aus, außer das test belegt aber nicht genutzt wird...
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Di 07.03.06 13:16 
ja, wie soll sich der fehler schon outen?
wie geschrieben, die bedingung

if Parent.Controls[i] is TEdit then

wird nie erfüllt => es wird halt einfach der darunter stehende code eben nicht durchlaufen...
punker76
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41


D5 Prof, D5 Ent, D7 Pers
BeitragVerfasst: Di 07.03.06 13:22 
Titel: Re: Alle Controls durchlaufen und Tedit controls herausfinde
kann es sein, dass diese funktion der scrollbox angehört?

wenn ja, dann solltest du vielleicht nicht parent als variable nehmen

mfg

user profile iconChristoph Englmann hat folgendes geschrieben:
hallo,

habe eine scrollbox, in der es verschiedene Komponenten gibt.

Nun möchte ich alle Komponenten in der Scrollbox durchlaufen und wenn es sich um eine TEdit Komponente handelt und diese dann (2.if Bedingung) einen bestimmte Tag hat, soll z.B. ReadOnly auf false gesetzt werden.

hier der code
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:
procedure Aktivieren_Deaktivieren_Textfelder(Parent :TWinControl);
var
  i :integer;
  test :Tcontrol;
begin

  for i := 0 to Parent.ControlCount-1 do
  begin
    //TEdit
    test := Parent.Controls[i];
    if Parent.Controls[i] is TEdit then
    begin
      if Parent.Tag = Aktor then
      begin
        (Parent.Controls[i] as TEdit).Color := clblack;
        (Parent.Controls[i] as TEdit).ReadOnly := false;
      end
      else
      begin
        (Parent.Controls[i] as TEdit).Color := clgray;
        (Parent.Controls[i] as TEdit).ReadOnly := true;
      end;
    end;

  end;

end;


Problem ist, dass mir das Programm nie in die Erste If-Bedingung einspringt, sprich die Bedingung
if Parent.Controls[i] is TEdit then
wird nie erfüllt, obwohl sehr viele Edit Komponenten in der ScrollBox vorhanden sind.


danke
christoph

_________________
Punk's not dead!
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 07.03.06 13:43 
Erste Möglichkeit: Im Controls-Feld stehen nur die 'Kinder', und nicht alle Komponenten.
Zweite Möglichkeit: Vergleich doch mal 'MyEdit.Parent.ClassName' mit dem 'Parent.ClassName', mit dem Du die Routine aufrufst.
Dritte Möglichkeit: Liste mal alle Kinder vom Parent-Parameter auf (über ClassName).

Vierte Möglichkeit: Sourcen her! :wink:

_________________
Na denn, dann. Bis dann, denn.
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Di 07.03.06 14:21 
Also erstmal sollte die procedure zu einem Objekt gehören, so find ich das nicht so gut... Funktionieren sollte es trotzdem! Was übergibst du denn als Parent? Hoffentlich die Scrollbox! Und dann sollte das eigentlich tun...



MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Di 07.03.06 14:25 
danke für die antworten, hab das problem jetzt:

in der scrollbox befinden sich groupboxen darauf wieder groupboxen und darauf erst die textfelder...

meine schleife über die scrollbox läuft nur die ersten groupboxen durch und kommt gar nicht bis zu den textfeldern...

frage:
wie krieg ich es hin, dass die schleifen ALLES, was in der scrollbox ist durchläuft, also bis zu den Textfeldern durchdringt?

danke
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Di 07.03.06 14:49 
Rekursion :D Etwa so:

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:
procedure Aktivieren_Deaktivieren_Textfelder(Parent :TWinControl);
var
  i :integer;
  test :Tcontrol;
begin

  for i := 0 to Parent.ControlCount-1 do
  begin
    //TEdit
    test := Parent.Controls[i];
    if Parent.Controls[i] is TEdit then
    begin
      if Parent.Tag = Aktor then
      begin
        (Parent.Controls[i] as TEdit).Color := clblack;
        (Parent.Controls[i] as TEdit).ReadOnly := false;
      end
      else
      begin
        (Parent.Controls[i] as TEdit).Color := clgray;
        (Parent.Controls[i] as TEdit).ReadOnly := true;
      end;
    end else
      Aktivieren_Deaktivieren_Textfelder(Parent.Controls[i]);

  end;

end;


Weitere Infos: de.wikipedia.org/wiki/Rekursion



MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Di 07.03.06 15:03 
user profile iconChristoph Englmann hat folgendes geschrieben:
danke für die antworten, hab das problem jetzt:

in der scrollbox befinden sich groupboxen darauf wieder groupboxen und darauf erst die textfelder...

meine schleife über die scrollbox läuft nur die ersten groupboxen durch und kommt gar nicht bis zu den textfeldern...

[highlight]frage:
wie krieg ich es hin, dass die schleifen ALLES, was in der scrollbox ist durchläuft, also bis zu den Textfeldern durchdringt?[/highlight]

danke


Moin :-)

*grr* diese Info hättest Du auch etwas früher geben können ;-)

Antwort: damit

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:
procedure Aktivieren_Deaktivieren_Textfelder(XYZ :TWinControl);
var
  i :integer;
  test :Tcontrol;
begin

  for i := 0 to XYZ.ControlCount-1 do
  begin
    //TEdit
    test := XYZ.Controls[i];

    if test is TGroupBox then
      Aktivieren_Deaktivieren_Textfelder(test as TWinControl);


    if test is TEdit then
    begin
      if XYZ.Tag = 123 then    
      begin
        (test as TEdit).Color := clblack;
        (test as TEdit).ReadOnly := false;
      end
      else
      begin
        (test as TEdit).Color := clgray;
        (test as TEdit).ReadOnly := true;
      end;
    end;

  end;

end;


Den 'Parameter' bzw die Variable Parent hab ich mal zu XYZ geändert. Parent ist ein reserviertes Wort bzw stellt ne Eigenschaft da...

Gruß

//EDIT: etwas zu spät, Mr.Saint war etwas fixer :-(
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 07.03.06 15:25 
user profile iconraiguen hat folgendes geschrieben:
//EDIT: etwas zu spät, Mr.Saint war etwas fixer :-(

Aber Dein Code ist sicherer, denn wenn bei MrSaints Code eine andere Komponente als TEdit oder TGroupBox auf dem Formular ist (z.B. TLabel) führt das sehr schnell zu einer Zugriffsverletzung.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Di 07.03.06 15:28 
Nochmal verbessern (Parameter auf 'aParent' und rekursiv, wenn Test is TWinControl (und nicht nur TGroupBox)):
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:
procedure Aktivieren_Deaktivieren_Textfelder(aParent :TWinControl);
var
  i :integer;
  test :Tcontrol;

begin
  for i := 0 to aParent.ControlCount-1 do
  begin
    //TEdit
    test := aParent.Controls[i];
    if test is TWinControl then
      Aktivieren_Deaktivieren_Textfelder(test as TWinControl);

    if test is TEdit then
    begin
      if aParent.Tag = 123 then    
      begin
        (test as TEdit).Color := clblack;
        (test as TEdit).ReadOnly := false;
      end
      else
      begin
        (test as TEdit).Color := clgray;
        (test as TEdit).ReadOnly := true;
      end;
    end;

  end;

end;

_________________
Na denn, dann. Bis dann, denn.
Christoph Englmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Di 07.03.06 16:46 
super, super, super....danke, danke, danke...

funktioniert einwandfrei...
(nur die eine Zeile muss anstatt
if aParent.Tag = 123 then

if test.Tag = 123 then

heissen...