Board index » delphi » Run-time expression evaluation

Run-time expression evaluation

Hi everybody!

Does anyone know how to do expression evaluation at run-time?  More
particularly, how by knowing the name of a public variable, or object as
a "string" find out the value.

I.e., I'd like to have a function:

function EvaluateExpression(AExpression: string): string;

which does:

EvaluateExpression('Application.Active')   ->  'True'
EvaluateExpression('Application.Exename')  ->  'c:\somepath\program.exe'
EvaluateExpression('Form1.Visible')        ->  'True'
EvaluateExpression('Form1.Tag')            ->  '0'
EvaluateExpression('Unit1.SomePublicVar')  ->  '10'

just like the de{*word*81} does it in the 'Watches' window, how how the
hints do the evaluation when the mouse is positioned over a
variable/property.

Thank you.

Serge.

 

Re:Run-time expression evaluation


In article <38ED01B2.32B6D...@hq.idt.net>, Serge Aleynikov
(se...@hq.idt.net) says...

Quote
> Does anyone know how to do expression evaluation at run-time?  More
> particularly, how by knowing the name of a public variable, or object as
> a "string" find out the value.

If you could be satisfied with *published* variables the TypInfo unit
should give you all you need (D5 even has a GetPropertyValue...).
But if you really want *public* variables, you're pretty much out of luck
(or into reading the symbol-info).

M.

--
ROOTS 2000, Bergen, April 27-28
{*word*19}burn, Coplien, Fowler, Groven, Reenskaug, Reich, Nygaard
Patterns, Use Cases, Refactoring, XP, UML, OO ++
http://roots.dnd.no

Re:Run-time expression evaluation


What I'd suggest to Serge is this:  "okay, that's a
Visual-Basic-inspired *solution* to a problem ... but what is the
ultimate problem that you are trying to solve here?"  For that problem,
whatever it is, there will prove to be an appropriate Delphi-oriented
solution.  Perhaps it will prove to be a more elegant and durable one.

That is to say... given the problem that you, Serge, conclude "must be
solved by run-time expression evaluation because that is how I would
solve the problem under Visual Basic ..."  what IS the problem?  

Quote
>Martin Larsson wrote:

> In article <38ED01B2.32B6D...@hq.idt.net>, Serge Aleynikov
> (se...@hq.idt.net) says...
> > Does anyone know how to do expression evaluation at run-time?  More
> > particularly, how by knowing the name of a public variable, or object as
> > a "string" find out the value.

> If you could be satisfied with *published* variables the TypInfo unit
> should give you all you need (D5 even has a GetPropertyValue...).
> But if you really want *public* variables, you're pretty much out of luck
> (or into reading the symbol-info).

> M.

> --
> ROOTS 2000, Bergen, April 27-28
>{*word*19}burn, Coplien, Fowler, Groven, Reenskaug, Reich, Nygaard
> Patterns, Use Cases, Refactoring, XP, UML, OO ++
> http://roots.dnd.no

--
------------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)

- Show quoted text -

Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  "Click click, it's fixed!" {tm}
> http://www.sundialservices.com/products/chimneysweep

Other Threads