alnickels 0 Posted September 1, 2020 Is there a way to tell if a variable or class property exist within delphi at runtime? Share this post Link to post
David Heffernan 2345 Posted September 1, 2020 These things are determined at compile time. You can't declare either at run time. So why do you feel this a run time issue? Share this post Link to post
aehimself 396 Posted September 1, 2020 Yes, it does (but I don't know since when): Type TMyClass = Class public Class Var Counter: Integer; Constructor Create; ReIntroduce; End; Constructor TMyClass.Create; Begin Inc(Self.Counter); End; Procedure TForm1.Button1Click(Sender: TObject); Var v1, v2: TMyClass; Begin v1 := TMyClass.Create; v2 := TMyClass.Create; ShowMessage(IntToStr(TMyClass.Counter)); // Will show 2 End; Share this post Link to post
Remy Lebeau 1400 Posted September 1, 2020 (edited) 45 minutes ago, alnickels said: Is there a way to tell if a variable or class property exist within delphi at runtime? Are you looking for an RTTI solution to detect at run-time whether or not a given class type has declared a given class variable/property at compile-time? What is the end goal here that you are trying to accomplish? Edited September 1, 2020 by Remy Lebeau Share this post Link to post
alnickels 0 Posted September 1, 2020 Remy that will work. The application will read xml and get a variable or property name. If variable or property exists we will take certain actions depending on its value. Share this post Link to post
Remy Lebeau 1400 Posted September 1, 2020 (edited) 1 hour ago, alnickels said: Remy that will work. The application will read xml and get a variable or property name. If variable or property exists we will take certain actions depending on its value. Well, that is pretty easy to accomplish using TRttiContext.GetType() or TRttiContext.FindType(), and then using TRttiType.GetField() and TRttiType.GetProperty(). Edited September 1, 2020 by Remy Lebeau 1 Share this post Link to post
Stefan Glienke 2007 Posted September 2, 2020 RTTI does not contain any information about class properties or vars/fields For clarification please see my P.S. in this post. Share this post Link to post