![]() |
Objekt durch String finden
Hallo!
Ich habe jetzt z.B. diesen Programmtext:
Delphi-Quellcode:
Jetzt möchte ich das ganze zusammenfassen. Ich habe hier schon von einer Möglichkeit gelesen, finde es aber nicht mehr.
Combobox9.Items:=ComboBox8.Items;
Combobox10.Items:=ComboBox8.Items; Combobox11.Items:=ComboBox8.Items; Combobox12.Items:=ComboBox8.Items; Combobox13.Items:=ComboBox8.Items; Combobox14.Items:=ComboBox8.Items; Combobox15.Items:=ComboBox8.Items; Combobox16.Items:=ComboBox8.Items; Combobox17.Items:=ComboBox8.Items; Combobox18.Items:=ComboBox8.Items; Combobox19.Items:=ComboBox8.Items; Combobox20.Items:=ComboBox8.Items; Combobox21.Items:=ComboBox8.Items; ComboBox9.ItemIndex:=0; ComboBox10.ItemIndex:=0; ComboBox11.ItemIndex:=0; ComboBox12.ItemIndex:=0; ComboBox13.ItemIndex:=0; ComboBox14.ItemIndex:=0; ComboBox15.ItemIndex:=0; ComboBox16.ItemIndex:=0; ComboBox17.ItemIndex:=0; ComboBox18.ItemIndex:=0; ComboBox19.ItemIndex:=0; ComboBox20.ItemIndex:=0; ComboBox21.ItemIndex:=0; Es ging so, das man einen string bildet, ein objekt sucht, das so heißt wie der string und dann die eigenschaft des objekts verändert. kann mir jemand schreiben wie das geht? |
Re: Objekt durch String finden
Das geht mit FindComponent.
Dann könntest du alle ComboBoxen in einer Schleife durchgehen. Z.B.:
Delphi-Quellcode:
Florian
for i := 9 to 21 do
TComboBox(FindComponent('ComboBox' + IntToStr(i))).ItemIndex := 0; |
Re: Objekt durch String finden
so:
Delphi-Quellcode:
for i:=9 to 21 do (FindComponent('ComboBox' + IntToStr(i)) as TComboBox).Items:=ComboBox8.Items;
for i:=9 to 21 do (FindComponent('ComboBox' + IntToStr(i)) as TComboBox).ItemIndex:=0; |
Re: Objekt durch String finden
Danke! :thumb:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz