Autor Beitrag
Josef-B
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Di 27.02.07 22:25 
Ich habe so ca. 20 DBedits.

dbedit1, dbedit2, dbedit3 usw.

Jetzt will ich die alle auf readonly setzen.

Habe mir das ungefähr so gedacht:

ausblenden Delphi-Quelltext
1:
2:
3:
for i:= 0 to 19 do
  begin
  dbedit(i).????.readonly := true;


So als array gehts sicher nicht, aber wie? oder bin ich da total auf dem Holzweg und ich muss
die dann alle einzeln auf readonly setzen?
Blawen
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 616
Erhaltene Danke: 33

Win XP, Vista, 7
Delphi 5 Prof., BDS 2006 Prof. RAD Studio XE
BeitragVerfasst: Mi 28.02.07 00:16 
"Findcomponent" dürfte Dich weiterbringen

_________________
Es kompilert, wir können ausliefern.
Und es kompiliert wieder - das Update ist fertig - bitte 100 Euro ;-)
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mi 28.02.07 13:56 
Hi
Wenn deine Objektnamen mit einer laufenden Integerzahl enden, denn ist FindComponent der richtige Weg.

ausblenden Delphi-Quelltext
1:
TDBEdit(FindComponent('DBEdit'+IntToStr(i))).readonly := true;					


Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mi 28.02.07 14:52 
user profile iconoldmax hat folgendes geschrieben:
Wenn deine Objektnamen mit einer laufenden Integerzahl enden..


Nur zur Klarstellung :

das mit der Nummer am Schluss des Bezeichners ist keine Bedingung ! Sieht man des öfteren, dass die Leute das glauben.

Das hier ginge auch :

ausblenden Delphi-Quelltext
1:
TDBEdit(FindComponent('DB'+IntToStr(i)+'Edit')).readonly := true;					


Die Zahl im Namen dient lediglich zur Vereinfachung von Schleifen, zu sonst nichts.

_________________
Gruß
Hansa
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mi 28.02.07 21:31 
Hi
Natürlich hast du recht, aber es ist übersichtlicher mit der Zahl hinten, als wenn sie mitten im Namen steht.
Du kannst die Namen auch völlig durcheinander mit dem Object in eine TStringlist schreiben und über den Index zuordnen
MyList:=TStringlist.Create;
MyList.AddObject('erstesObject',MyEdit);
Auch damit ist ein Indizierter Zugriff auf verschiedene Objecte möglich. der Wege nach Rom sind halt viele....
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
Josef-B Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 293

2003 Server, Win7, Win8
Delphi 2010 Pro, Firebird 2.5
BeitragVerfasst: Mi 28.02.07 23:09 
Egal ob der Zähler da jetzt vorne hinten oder in der Mitte steht, ich habs so gemacht, und es klappt wunderbar.

Allerdings hatte ich die Schleife mit findkomponent zuerst im AfterOpen von einer TIBQuery, da bekam ich eine Zugriffsverletzung. Dann habe ich ich das in eine eigene Prozedur ausgelagert, da klappte das. Wieso das sein kann, weiss ich nicht.