Hello Human.
What you want can easily be done using Delphi's RTTI. Just google for
RTTI and you'll find some documentation plus some samples. You'll also
find components that do what you want but if you like rolling your own
(or need the extra flexibility afforded by rolling your own) go ahead,
is not nearly as difficult as it sounds. RTTI provides the means to get
a list of property names given a object class or an object instance and
it provides the means to get the value of a property given a object
instance and a property name.
It can't be done the way you suggested because of the way parameter
passing occurs. When you call a function taking one integer using
Delphi's default calling convention, the integer parameter will be set
as one of the registers (EAX?) and then control goes to the procedure.
From within the procedure you can't tell if the parameter comes from a
variable, is the result of some computation or is in fact a constant!
Top, Left, FontSize are NOT variables, they are properties. There's a
huge difference between the two: When you try to get the value of a
property the compiler will call it's GetXXX function transparently. When
you try setting it's value the compiler will actually call it SetXXX
method. The good news is properties get RTTI, variables do not.
Human wrote:
> I want to know if it is possible to get the name of a variable as text/string
> (I know this might
> be impossible).
>
> For example I need a function that will accept as input a variable and will
> return a string that
> is the name of that variable. If my variable is FontSize the function will
> return 'FontSize'.
>
>
> More examples:
> If my function will be this:
> function ConvertToString(AVariable: integer): string;
> then running this program:
>
> ---------------------------
> var FontSize: integer;
> s: string;
> begin
> s:= ConvertToString(FontSize);
> end;
> ---------------------------
>
> s will be 'FontSize'.
>
>
> I want to use this to store my program's forms state on the HDD in a INI file
> then restore it when
> the program starts again.
> I already do this by using something like this:
>
> MyIniFile:= TCIniFile.Create(GetApplicationDir+'settings.ini');
> With MyIniFile DO
> With MainForm DO
> begin
> Left := ReadInteger('WindowState', 'left', 50);
> top := ReadInteger('WindowState', 'top' , 50);
> Width := ReadInteger('WindowState', 'width' , 750);
> Height := ReadInteger('WindowState', 'height', 550);
> checkboxes, etc...
> end;
>
> but I would like to simplify it to something like
>
> SaveToIni(Left);
> SaveToIni(Top);
> etc...
>
>
>
> -----------------------------------------------
> -----------------------------------------------
> -----------------------------------------------
>
>
> I realized that in a big program with lots of windows and buttons I can spend
> lots of time coding
> the store/restore functions.
> It is also very error prone.
>
> There is a VERY good VCL that can store automatically this information for me?
> I tried several VCLs but all had some problems/limitations.
>
>
>
>
>
> If I choose Christianity then the Islamic will say I'm a pagan.
> If I choose Islamic then the Buddhism will say I'm a pagan.
> If I chose Buddhism then the Jewish will say I'm pagan.
> If I choose no God then everybody will say I'm pagan.
> Please, can I be free? Can you NOT tell me how I should live MY life?
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
>
>
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk