I want to load all classes from a current project in a TList. If I read the dpr file like a normal file it will return me only strings. I want to get all the classes defined in the dpr file and their names. Does someone know how to do that?
Share
In the Delphi IDE, all classes are available in the .dcu files, corresponding to each .pas files. Those .dcu files have a proprietary binary evolving format, so can not be used outside the IDE.
At program execution, and within the exe file, there is no list of all existing classes. You can retrieve information about a known class using the RTTI functions (see
TypInfo.pasand relatives as stated by the Embarcadero documentation). So at runtime, you just can retrieve information from a given class: you can use e.g.anObject.ClassNameoranObject.ClassTypemethods.But I suspect you want to retrieve all classes defined in a project, from its source code. For this, you will need a source code parser, which will extract the logic from the .pas files. In short, the parser will read the .dpr then all necessary .pas files source code, interpret the object pascal type definitions, and create a list of units, classes, methods and properties. There are several parsers around: see for instance PasDoc or the version we embedded in SynProject.
Additional note – for an exhaustive list: If you generate a .map file during the compilation, this text file will contain all symbol names of the executable, including the classes. You’ll have to parse it, but won’t have much information to deal with, since there is no easy way of guessing if each symbol is a class or a record, for instance, or about classes inheritances or properties… This .map is intended about execution debugging, not RTTI.