![]() |
Property Typ ermitteln
Moin !
Ich habe da ein Stück Code (C = TComponent):
Delphi-Quellcode:
Das funzt auch ganz gut. Allerdings gibts da ein kleines Problem. Items kann vom Typ TStrings sein aber ein Popupmenü hat auch eine Items Property die ist aber nicht vom Typ TStrings. Das kanllt natürlich.
if IsPublishedProp(C, 'Items') then begin
SubNode := XMLDoc.SelectSingleNode('/Language/' + Form.Name + '/' + C.Name + '/Items'); ... SetCDataChild(SubNode, (GetObjectProp(C, 'Items') as TStrings).Text); end; Wie kann ich nun überprüfen ob Items auch wirklich vom Typ TStrings ist? Geht das irgendwie mit PropType? Folgendes geht jedenfalls mal nicht: PropType(C, 'Items') = TStrings :| Ist aber auch klar, weil PropType was ganz anderes zurück liefert ... Any hints ? :gruebel: |
Re: Property Typ ermitteln
Wie wär's mit
Delphi-Quellcode:
Items.ClassNameIs('TStrings')
|
Re: Property Typ ermitteln
Du könntest es besser mit "is TStrings" und danach bei Erfolg mit einem "harten" Cast machen ( TStrings(Objekt) ). ClassNameIs() würde Nachfahren von TStrings, welche auch die Text-Property ausschliefen afaik.
Viele Grüße |
Re: Property Typ ermitteln
vermutlich so?
Delphi-Quellcode:
GetPropInfo(C, 'Items').PropType.Kind = tkString
[add]
Delphi-Quellcode:
PS: kannte diese Funktion vorher auch nicht, aber wenn man mal nachsieht, was alles statt nur IsPublishedProp existiert .....
PropType(C, 'Items') = tkString
[add2] :oops: er wollte es ja andersrum .. dann siehe weiter unten |
Re: Property Typ ermitteln
Moin !
Delphi-Quellcode:
So tut das.
if IsPublishedProp(C, 'Items') then begin
if GetObjectProp(C, 'Items') is TStrings then begin SubNode := XMLDoc.SelectSingleNode('/Language/' + Form.Name + '/' + C.Name + '/Items'); if SubNode = NIL then begin Knoten := XMLDoc.CreateElement('Items'); SubNode := Node.AppendChild(Knoten); end; SetCDataChild(SubNode, (GetObjectProp(C, 'Items') as TStrings).Text); end; end; Wie immer stehe ich tief in eurer Schuld. Danke :thumb: :dp: |
Re: Property Typ ermitteln
GetObjectProp will hier aber nur Objekte und keine Klasse (C = TComponent) :gruebel:
|
Re: Property Typ ermitteln
Zitat:
|
Re: Property Typ ermitteln
hmmm *nochmalüberleg* ... OK, wenn C wie TComponent und nicht C wie Class bzw. O wie Object ... dann könntest du doch Recht haben :oops:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:25 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