Autor Beitrag
Uli Schoch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Mi 15.08.07 09:18 
Hallo
Ich möchte bei 32 Komponenten, welche L1..L32 heissen, den Top-Wert verändern, d.h. neu berechnen. Es gibt doch irgendeinen Trick, die Komponenente per Name anzusprechen. Dann kann ich so etwas machen:

for n:=1 to 32 do <Komponentenname??>('L'+IntToStr(n).Top:=20*n;

Wie schreibt man <Komponentenname??> genau?

Danke für Hinweise

Uli
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 15.08.07 09:21 
ausblenden Delphi-Quelltext
1:
for n:=1 to 32 do FindComponent('L'+IntToStr(n)).Top:=20*n;					

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Uli Schoch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Mi 15.08.07 09:37 
Salü Marco
So gehts nicht, der Compiler findet .Top nicht. Ich habe dann probiert,

(FindComponent('L'+IntToStr(n)) as TApdStatusLight).Top:=24+(n-1)*18;

(TApdStatusLight ist der Typ der Komponente) Das geht zum Compilieren, gibt aber einen Laufzeitfehler "Zugriffsverletzung"

Warum wohl?

Gruss
Uli
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 15.08.07 09:41 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for n := 1 to 32 do
begin
  showmessage(inttostr(n));
  TApdStatusLight(FindComponent('L'+IntToStr(n))).Top:=24+(n-1)*18; 
end;

Vielleicht gibt es die Komponten ja nicht alle.
Vielleicht liegen die Komponenten auch auf einem anderen Formular. Dann schreibe mal vor FindComponent den Namen der Form, auf der deine Kompos liegen,

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Uli Schoch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Mi 15.08.07 11:14 
Salü Marco
Ja, so gehts. Ich hab zwar noch lange geübt, weile die Zeile in einer With-Sequenz drin stand. Da hat das Findcomponent Mühe gehabt.

Gruss und besten Dank
Uli