I need to convert a huge number of constants from an application. Is it possible to get all the constants declared in a unit and their values, other then parsing the .pas file?
-
If you talk about string constants then localization tools might help. – ain Mar 20 '12 at 10:55
-
Most of them are string constants...I need to change their format, and I'm trying to do this by a routine, or another mechanism. But first of all, I need a list with them... – RBA Mar 20 '12 at 11:03
-
Why won't you just parse the file? – David Heffernan Mar 20 '12 at 13:26
-
This is what I will do. I tried to find out if there is another way to do it. – RBA Mar 20 '12 at 13:38
3 Answers
There is the Open Tools API to work with the IDE in an object oriented way. But I think it is not possible to list the constants of files.
I think the easiest way is to use grep or other similar RegEx program that can collect the string constants from files: ^\s*\w+\s*=\s*'.+?'\s*[;#\{\+]

- 448
- 4
- 13
It seems that this is not possible without parsing your unit and extract the constants. During the compilation constants are replaced by value, so it is impossible to get the value from them at runtime.
LE: maybe there is someone who can explain this in depth.

- 12,337
- 16
- 79
- 126
How about changing all CONST to ResourceString, re-building, and then dump the string resources using a resource editor like XN Resource Editor? That's how I'd approach it, if there were really THAT many of them.

- 15,620
- 5
- 37
- 62