Autor Beitrag
24karatboy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 09:42 
wie kann ich nen array schreiben vom type TSpeedButton ?

also mein vorhaben ist ich habe viele zuweisungen auf tspeedbutton1,2,3,4,5,6.caption

so jetzt möchte ich meinen programmcode aber ein wenig modifizieren (vereinfachen).

ich hab mir das so gedacht taste : array[0..9] of TSpeedButton.

und ich sollte die captions doch dann mit taste[0..9] ansprechen können oder ?
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 28.06.07 09:58 
(a) Was spricht gegen ausprobieren? (TRIAL AND ERROR)!
(b) FindComponent + F1 könnte dich auch weiterbringen!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 10:06 
Zitat:
(b) FindComponent + F1 könnte dich auch weiterbringen!

Das Abspeichern der Referenzen in einen Array ist aber imho die bessere lösung.

_________________
Markus Kinzler.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 28.06.07 10:20 
user profile iconmkinzler hat folgendes geschrieben:
Zitat:
(b) FindComponent + F1 könnte dich auch weiterbringen!

Das Abspeichern der Referenzen in einen Array ist aber imho die bessere lösung.

Wenn man nach Byte bezahlt wird :D !

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 10:24 
ich verstehe nicht wie mir findcomponent weiter helfen könnte hab auch noch nie damit gearbeitet
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 10:26 
ausblenden Delphi-Quelltext
1:
function FindComponent(const taste:string): TComponent					


und in taste sollte dann speedbutton drinne stehen ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 10:41 
ausblenden Delphi-Quelltext
1:
(Form.FindComponent('Speedbutton1') as.TSpeedButton).<Eigenschaft>;					

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 10:43 
sorry aber irgendwie versteh ich den befehl nicht die oh hat mir auch nicht wirklich geholfen kann einer mal anz kurz und bündig erklären ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 10:49 
Die Funktion liefert dir eine Referenz auf eine Komponente zurück, welche den übergebenen Namen hat. Diese kann man dan in den entsprechenden Typ Casten kann ( ... as <Typ>). Mit dieser referenz kann man dann arbeiten.

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 10:53 
ja aber wodrinn wird gespeichert was findcomponent gefunden hat ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 10:56 
Je nach wohin du das Ergebnis zuweist
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Variable:
var
   sb: TSpeedbutton;
...
   sb := (Form.FindComponent('Speedbutton1') as.TSpeedButton);


Ohne
  with (Form.FindComponent('Speedbutton1') as.TSpeedButton) do

Direkte Manipulation
ausblenden Delphi-Quelltext
1:
   (Form.FindComponent('Speedbutton1') as.TSpeedButton).Caption := 'BlaBla';					

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 11:13 
seh ich das richtig das ich dann für jede caption abfargen muss mit findcomponent oder eine abfrage in ne schleife packe ? wäre das mit nem array für meinen fall nicht sinnvoller ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 11:15 
Ja, was ich ja in www.delphi-forum.de/....php?p=448640#448640 schon beschrieben habe

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 11:19 
das array hab ich so erzeugt taste : array[0..9] of TSpeedButton.

aber ansprechen kann ich es mit taste[0],taste[1] etc. irgendwie nicht wodran liegt das ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 11:21 
ja du hast einen Array mit leeren Referenzen erzeugt.

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 11:22 
sorry das ich mich hier gerade so doof anstelle aber ich weiss echt nicht wieso das nicht funktioniert ?

was meinst du mit leeren referenzen ? ich habe array sonst immer so erzeugt..
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 11:25 
T<Typ> ist nur eine Referenz, also ein Zeiger, der am Anfang auf Nil zeigt. Du mußt diese entweder auf vorhandene Objekte referenzieren lassen, z.B. wenn du sie in einer Schleife per FindComponent holst, oder du erzeugst die Komponenten dynamisch.

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 11:39 
und wie kann ich die so referenzieren das die global sind ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 28.06.07 12:23 
user profile icon24karatboy hat folgendes geschrieben:
und wie kann ich die so referenzieren das die global sind ?

Wie meinst du das?

_________________
Markus Kinzler.
24karatboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 110

Win XP
Delphi (Delphi Win32)
BeitragVerfasst: Do 28.06.07 12:26 
das das array dann global ist also das ist taste[0].caption taste[1].caption etc. von jeder procedure aus ansprechen kann.