List all constants from a unit - delphi

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?

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.

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*[;#\{\+]

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.

Related

What is the recommended way to make & load a library?

I want to make a small "library" to be used by my future maxima scripts, but I am not quite sure on how to proceed (I use wxMaxima). Maxima's documentation covers the save(), load() and loadFile() functions, yet does not provide examples. Therefore, I am not sure whether I am using the proper/best way or not. My current solution, which is based on this post, stores my library in the *.lisp format.
As a simple example, let's say that my library defines the cosSin(x) function. I open a new session and define this function as
(%i0) cosSin(x) := cos(x) * sin(x);
I then save it to a lisp file located in the /tmp/ directory.
(%i1) save("/tmp/lib.lisp");
I then open a new instance of maxima and load the library
(%i0) loadfile("/tmp/lib.lisp");
The cosSin(x) is now defined and can be called
(%i1) cosSin(%pi/4)
(%o1) 1/2
However, I noticed that a substantial number of the libraries shipped with maxima are of *.mac format: the /usr/share/maxima/5.37.2/share/ directory contains 428 *.mac files and 516 *.lisp files. Is it a better format? How would I generate such files?
More generally, what are the different ways a library can be saved and loaded? What is the recommended approach?
Usually people put the functions they need in a file name something.mac and then load("something.mac"); loads the functions into Maxima.
A file can contain any number of functions. A file can load other files, so if you have somethingA.mac and somethingB.mac, then you can have another file that just says load("somethingA.mac"); load("somethingB.mac");.
One can also create Lisp files and load them too, but it is not required to write functions in Lisp.
Unless you are specifically interested in writing Lisp functions, my advice is to write your functions in the Maxima language and put them in a file, using an ordinary text editor. Also, I recommend that you don't use save to save the functions to a file as Lisp code; just type the functions into a file, as Maxima code, with a plain text editor.
Take a look at the files in share to get a feeling for how other people have gone about it. I am looking right now at share/contrib/ggf.mac and I see it has a lengthy comment header describing its purpose -- such comments are always a good idea.
For principiants, like me,
Menu Edit:configure:Startup commands
Copy all the functions you have verified in the first box (this will write your wxmaxima-init.mac in the location indicated below)
Restart Wxmaxima.
Now you can access the functions whitout any load() command

How to use User-Input to address specific variables in Pascal (Eval/Exec?)

I'm trying to do something very specific in the fractal program Apophysis 7X, the scripting language in use is Pascal (the project is written in Delphi).
What I want to do:
Write a script that can dynamically address certain variables. In the program I have so called transforms, and each transform has multiple variations, new variations can be added by plugins, hence I do not know all names there could be.
The variables are addressed like this:
Transform.Linear:=Sin(Pi*(FrameCount / FrameQuantity));
The Variation that is to be changed might not be Linear though, but a dozen other words, like Spherical or Zcone.
If eval would work I'd assume the solution to be something like this:
VariationName:=User-Input;
eval('Transform.' + VariationName + ':=Sin(Pi*(FrameCount / FrameQuantity));')
As far as I know though, there is no such thing like eval or exec in Pascal (Tried: Eval/eval/Exec/exec). Searching other sites and the internet didn't turn up any ideas either.
So the question is how can I use the User-Input to address those variables? Obviously:
Transform.'User-Input':=Sin(Pi*(FrameCount / FrameQuantity));
will not work. Since I don't know all names up front I can't just use an array or anything static either. Any ideas would be greatly welcome.
What you want to do is called Reflection. Delphi does have support for it (they call it Extended RTTI). Give a look at the functions IsPublishedProp and SetPropValue.

XQuery: How to get system path separator?

I would like to know if there is a possibility to get the system path separator inside my XQuery code without special libraries?
No. There's nothing defined in the XQuery 1.0 or XQuery 3.0 specs to identify details of the filesystem.
However, using fn:doc(), you should be able to reference filesystem URIs generally by preceding the file name with file:/// and using / as a separator for directory.
As already mentioned, I don't think it is possible to achieve this by using standard XQuery functionality. However, depending on what processor you are using, it is quite likely that you can use Java bindings. I am aware that at least BaseX, eXist and Saxon support this.
By using this technique you can get the separator
declare namespace system="java:java.lang.System";
system:getProperty("file.separator")
Or if your processor supports the expanded QName notation you can also write
Q{java:java.lang.System}getProperty("file.separator")

Can I get lex to put out a yylex() function with a different name?

I want to have two lexers in one project, and I don't want to run into problems with having multiple yylex functions in the build. Can I make lex output with a different prefix?
You can use the -Pprefix parameter for flex in your makefile. Using flex -Pfoo you would effectively prefix all yy generated functions. Have a look at the manual page for further details.
flex lets you do that. Just define the YY_DECL macro. Dunno about actual Unix(tm) lex(1) though.
You could build a C++ lexer. This means all the state information is held in an object.
Then it is just a matter of using the correct object!

How to tell what types are defined in a Delphi DCU?

I have a set of compiled Delphi dcu files, without source. Is there a way to determine what types are defined inside that dcu?
To find out what's in a unit named FooUnit, type the following in your editor:
unit Test;
interface
uses FooUnit;
var
x: FooUnit.
Press Ctrl+Space at the end, and the IDE will present a list of possible completion values, which should consist primarily, if not exclusively, of type names.
You could have a look at DCU32INT, a Delphi DCU decompiler. It generates an .int file that is somehow readable but not compilable, but if you only want to determine the types defined, this could be enough.
The DCU format is undocumented, last I checked. However, there is a tool I found that might give you some basic info called DCUtoPAS. It's not very well rated on the site, but it might at least extract the types for you. There is also DCU32INT, which might help as well.
Otherwise, you might just have to open the file with a hex editor and dig around for strings.

Resources