Autor Beitrag
beljo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 09:48 
hi Leute,
hab vogendes probiert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i:= 82 to 103 do
   if (Components[i] is TEdit) then
    begin
     (Components[i] as TEdit).Visible:= false
     end;

Also die Textfelder von 82 bis 103 sollen damit unsichtbar gemacht werden.Leider sind sie dennoch sichtbar hab ich irgendwas falsch gemacht? ich kann den Fehler nicht finden, ausserdem gib es keine Fehelermeldung.
Danke im Vorraus


Moderiert von user profile iconTino: Topic aus Dateizugriff verschoben am Mi 29.03.2006 um 11:14
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.03.06 10:23 
Moin!

Du darfst nicht vom Index in Components[] auf den Namen des Controls schließen! :mahn:

Fazit: Alle Einträge in Component[] durchlaufen und den Namen vergleichen oder gleich FindComponent nehmen. ;)

cu
Narses
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 10:49 
das mit dem findComponent hab nicht so richtig verstanden´, deshalb hab ich es mit einem Vergleich probiert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i:= 82 to 103 do
   if Components[i] is Tedit(i) then
    begin
     (Components[i] as TEdit).visible:= false
       end;

Leider macht Delphi da nicht mit...
Tja bin ja auch in erster Linie kein Programmierer ;-)
kannst mir jemand es bitte leichtverständlich erklären?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 29.03.06 10:58 
Alles was du auf der Form ablegst sind Komponenten. Die Nummerierung muss nicht den Bezeichnern entsprechen! Also kann Edit23 die Komponente 44 sein, u.s.w. . Damit funktioniert deine Überprüfung schon nicht mehr.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.03.06 11:00 
Moin!

Welchen Sinn hat es, zweimal den gleichen Code in den Beitrag zu setzen? :gruebel:

user profile iconbeljo hat folgendes geschrieben:
das mit dem findComponent hab nicht so richtig verstanden

Zeig doch mal deinen Code, mit dem du es probiert hast (Beispiele gibt´s ja hier im Forum genug). ;)

cu
Narses
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 11:12 
user profile iconjasocul hat folgendes geschrieben:
Die Nummerierung muss nicht den Bezeichnern entsprechen! Also kann Edit23 die Komponente 44 sein, u.s.w. . Damit funktioniert deine Überprüfung schon nicht mehr.

Wow, sowas gemeines aber...
naja hier erstmal mein Quellcode
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TSM.FormCreate(Sender: TObject);                // Vorbelegung auf '0'
var i: integer;                                          // lokale Laufvariable
begin
 Edit60.Visible:= false;
 Edit61.Visible:= false;
 Edit67.Visible:= false;
 Edit70.Visible:= false;
 Edit74.Visible:= false;
 Edit77.Visible:= false;
 Edit80.Visible:= false;
  for i:= 82 to 103 do
   if Components[i] = Tedit(i) then
    begin
     (Components[i] as TEdit).visible:= false
    end;
end;

ich wollte mir Schreibarbreit ersparen, deshalb mein Ansatz. Ausserdem wollte ich ja auch was Lernen ;-)
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 11:13 
zur Not schreibe ich alles aus, aber ich wüsste schon gerne wie man es vereinfachen kann
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 29.03.06 11:25 
Moin!

Ich meinte deinen FindComponent-Code, der nicht funktioniert! ;)

cu
Narses
ultra2k
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

XP x64
D7 Enterprise
BeitragVerfasst: Mi 29.03.06 11:33 
Wie wärs hiermit?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
uses StrUtils;

{...}

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  min, max, current: Integer;
  prefix: String;
begin
  min    := 3;
  max    := 4;
  prefix := 'Edit';

  for i := 0 to ComponentCount - 1 do
    if (Components[i] is TEdit) and (LeftStr(Components[i].Name, StrLen(PChar(prefix))) = prefix) then begin
      current := StrToInt(RightStr(Components[i].Name, StrLen(PChar(Components[i].Name)) - StrLen(PChar(prefix))));
      if (current >= min) and (current <= max) then
        (Components[i] as TEdit).Visible := False;
    end;
end;


Vielleicht nicht der beste Weg, aber du kannst festlegen wie dein Edit heißen soll, und in welchem bereich die Felder ausgeblendet werden sollen. Das mit dem Präfix is vielleicht nich verkehrt, wenn du soviele Editfelder hast :wink: dann kannste denen noch vernünftige Namen geben (AddressEdit, InfoEdit, ..)

_________________
...wenn NULL besonders groß ist, isses schon fast wie ein bisschen EINS!
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 12:03 
@ultra2k
hey da hat sich jemand wirklich einen Kopf gemacht, ist zwar wirklich etwas umständlich, aber bei vielen Textfeldern macht es durchaus sinn.

Danke an alle für eure Lösungsansätze und Vorschläge :-)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 29.03.06 12:45 
Du könntest dir die TEdits auch in einer TList merken und gegebenenfalls die TList durchgehen.
Bei so vielen TEdits würde ich sowieso vernünftige Bezeichner nehmen und nicht die automatische Nummerierung. Irgendwann muss man auf die Inhalte zugreifen und dann geht die Nummern-Sucherei los. Der Source wird dadurch absolut unlesbar.
(Nur so als Tipp am Rande)
ultra2k
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

XP x64
D7 Enterprise
BeitragVerfasst: Mi 29.03.06 12:55 
genau, und wer weiß bei 103 Editfeldern schon auf anhieb, welches wofür ist :shock:

Aber nur so am rande, was programmierste denn, das soviele Edits braucht :?:

_________________
...wenn NULL besonders groß ist, isses schon fast wie ein bisschen EINS!
direction4delphi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 84

WIN 95, WIN 98, WIN ME, WIN NT, WIN 2000, WIN XP, VISTA
D2 Prof, D4 Prof,D2005 Prof, Delphi4Php
BeitragVerfasst: Mi 29.03.06 13:52 
Geht auch ein wenig einfacher

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
  I: Integer;
begin
  For i:=82 to 103 do (FindComponent('Edit'+IntToStr(i)) as TEdit).visible:= False;
end;


mfg
direction4delphi

_________________
Warning: dates on calendar are closer than they appear.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 29.03.06 13:58 
Stimmt. An die Variante erinnere ich mich auch. Allerdings ist die in der Form gefährlich. Wenn Edit99 nicht existiert dürfte es eine Schutzverletzung geben.
Also erst mit FindComponent prüfen, ob es die Komponente gibt und dann die Eigenschaft setzen. Nicht beides in einem Zug.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 29.03.06 14:08 
Bei so vielen Edits würde ich auch dazu raten, im FormCreate einmal ein Array of TEdit mit den entsprechenden Edits zu befüllen, und dann über das Array auf die einzelnen zugreifen. Dürfte auf Dauer etwas leichter zu programmieren sein - und wahrscheinlich etwas performanter.

_________________
We are, we were and will not be.
beljo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129



BeitragVerfasst: Mi 29.03.06 15:01 
user profile iconultra2k hat folgendes geschrieben:


Aber nur so am rande, was programmierste denn, das soviele Edits braucht :?:


Um eure Neugier zu Befriedigen:
Das soll ein Projekt zur Berechnung von Elektrischen Maschinen werden.
neben den geometreischen Daten, die mich als Eingabefelder über 80 Edits gekostet haben, mussen auch Ausgabe-Edits bereitgestellt werden,wo die abgeleiteten Großen der Berechnung auch Dargestellt weren müssen.
Naja ein verdammt großes Projekt, aber ich habe ja euch ;-)
nochmal Danke für eure gnädige Hilfe
Vera
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 82

WinXP Home
Delphi 2005 Personal
BeitragVerfasst: Mi 29.03.06 15:03 
user profile iconGausi hat folgendes geschrieben:
Bei so vielen Edits würde ich auch dazu raten, im [...]

Ich würde pauschal dazu raten, dass gesammte Userinterface mal zu überdenken. ;-)
Fabian E.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 554

Windows 7 Ultimate
Visual Studio 2008 Pro, Visual Studion 2010 Ultimate
BeitragVerfasst: Mi 29.03.06 15:07 
Kannste nicht TMaskEdit ein edit für mehrere Werte nehmen?
Das wär villeicht einfacher.
Vera
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 82

WinXP Home
Delphi 2005 Personal
BeitragVerfasst: Mi 29.03.06 15:12 
Ein StringGrid würde vielleicht auch helfen.