![]() |
Anfängerfrage Objekte
Hallo zusammen,
da ich früher ausschließlich ohne Objekte programmiert habe, schlage ich mich mit der OOP ganz schön herum. Ein konkretes Beispiel: Ich habe in meiner Form 20 Comboboxen. Diese möchte ich bequem ansprechen können. z.B. Combobox[x].clear; wobei x eine Integervariable zwischen 0 und 20 sein soll. Das geht so aber leider nicht :? Könnt ihr mir einen Stoss in die richtige Richtung geben? Viele Grüße Daniel |
Re: Anfängerfrage Objekte
Hi
mit FindComponent ist das möglich. Hier ein Beispiel.
Delphi-Quellcode:
for i:= 0 to 20 do
(FindComponent('Combobox' + IntToStr(i)) as TComboBox).Clear; |
Re: Anfängerfrage Objekte
Das hat aber im eigentlichen Sinne nichts mit OOP zu tun.
|
Re: Anfängerfrage Objekte
Danke b1zZ!!
:-D |
Re: Anfängerfrage Objekte
FindComponent in einer Schleife ist aber nicht sehr performant. Ich würde es mal so versuchen (aus dem Kopf getippt):
Delphi-Quellcode:
for i := 0 to ComponentCount - 1 do
if Components[i] is TComboBox then TComboBox(Components[i]).Clear; |
Re: Anfängerfrage Objekte
Falls du es in ein Array packen willst:
Code:
var
Combobox: Array[0..20] of TCombobox; Initialisierung ( oncreate ): for i := 0 to 20 do begin Combobox[i] := TCombobox.Create(Self); Combobox[i].Parent := Self; // hab jetzt kein Delphi aber so ca müsste es gehn ... end; Zugriff: combobox[2].Clear; |
Re: Anfängerfrage Objekte
Da habe ich ja jetzt was zum probieren.
Danke! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:06 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