Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Objekt durch String finden (https://www.delphipraxis.net/65111-objekt-durch-string-finden.html)

maximus Caesar 12. Mär 2006 14:57


Objekt durch String finden
 
Hallo!
Ich habe jetzt z.B. diesen Programmtext:
Delphi-Quellcode:
  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;
Jetzt möchte ich das ganze zusammenfassen. Ich habe hier schon von einer Möglichkeit gelesen, finde es aber nicht mehr.

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?

Zacherl 12. Mär 2006 14:59

Re: Objekt durch String finden
 
Das geht mit FindComponent.
Dann könntest du alle ComboBoxen in einer Schleife durchgehen. Z.B.:

Delphi-Quellcode:
for i := 9 to 21 do
  TComboBox(FindComponent('ComboBox' + IntToStr(i))).ItemIndex := 0;
Florian

fLaSh11 12. Mär 2006 15:00

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;

maximus Caesar 12. Mär 2006 15:01

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