Generating a list of events in a Delphi/BCB Project - delphi

I would like to generate a list of events and methods assigned to them in a given BCB project. Is there a way to do this?

I don't think you can do this in a 100% reliable way. But maybe it's enough to just scan all the *.dfm's in your project folder for lines starting with " On".

There are DFM parser code available on the net.
http://www.felix-colibri.com/papers/colibri_utilities/dfm_parser/dfm_parser.html
FWIW, event is simply a property with method type.

I have just recently written a DFM file parser myself. My use case was to load a form and extract and replace some binary information from it. The library is written in Go, it is well-tested with RAD Studio source code and our own production code.
https://github.com/gonutz/dfm
You can use the parser, walk the tree in memory and generate what you need from it.

Related

Are there any tools that can give a class/struct diagram of a LUA project

Are there any tool that can give me a UML or table diagram on a set of related LUA files? If it can handle XML at the same time (the project has mixed LUA and XML that work together) that's a bonus.
No, the tool that you are looking for does not exist.

How to get type info from Go compiled packages in language x?

I want to write a simple editor with basic autocomplete functionality for the Go language as a pet project. How would one go about doing it? I took a look at the Go plugins for Eclipse and IntelliJ, but they were too big for me to comprehend (not to mention getting one to compile).
The Go standard library offers the building blocks for a Go parser which
you can use to parse the source files and look for function definitions and the like.
There's also the godoc command which
already does what you want: extracting method definitions and it's documentation. You may look in the
source code to see how godoc is
working or use godoc directly.
This editor written in Go projects has a manageable amount of code,
you may look into it.
The de facto standard approach to this problem is to use nsf's gocode. I have tried it only in Vim - it works very well.
Even though there's ready made support for specific editors, gocode is not editor specific. It's a daemon with a communication protocol. It is thus usable from any program.

any tools which scan code and give a list of functions which call a given function

here's my problem, I'm tidying up some old code which I've modified over the years and removing redundent functions,
I can do it the slow way & comment it out and see if the compiler throws an error.
But I'm just wondering if there are any tools which can which scan code and give a list of functions which call a given function.
I Had a look in ge-experts & icarus, but they only do this at the level of units & classes not down to functions.
any suggestions welcome,
many thanks, Brian
Recent versions of Delphi have "Search for References" available via context menu or Ctrl-Shift-Enter. This has the advantage over a simple "search in files" that it will find only references to the current function under the cursor and not also any function or other identifier with the same name.
Compile your project. Then, in the IDE, those lines that are accessed (rather than being dead code) will have a blue dot in the left margin:
No method is perfect, limitations of the one below are these:
the .MAP file will include functions that the linker cannot eliminate (for instance overrides of methods in classes touched by your code)
it will only give you method names, but if methods are overloaded multiple versions of these methods could be used
The big pro over using .MAP files is that they are easier to scan than blue dots in the code editor.
So it does answer your question to provide a list of functions. But that might not actually what you are after (:
Method using .MAP file:
change your project to include a detailed .MAP file
rebuild your project
the directory of your .EXE file now will include a .MAP file
scan the .MAP file for function names that are included in the .EXE
That .MAP file will exclude functions eliminated by the compiler and linker.
Those are a good indication of what 'dead' code you have.
In a similar way, you could use the JDBG information. That contains more context, but also requires you to write some tooling yourself.
For Pascal this is trivial. First make a list of all the functions, then for each function search for it in the text not following the word "function" and followed by a "(". Awk would be a good tool for doing this.
If your Delphi version is 2007 (or may be prior to it?), I strongly suggest you to consider using DGrok: Give it a try and you will see how capable it is (The demo app will tell).
As it was pointed out by the author, you still need to implement symbol table support, so that the tools can do refactorings or Find References: Roll your own...
Don't worry if you are stuck to Delphi, please head to
PasParse (The Delphi port of the DGrok parser that was originally written in C# !) by Turbo87.
Notice that Turbo87 has forked the original Joe White's Dgrok (latest release in 2008) (Update to VS2010 and add some documentation for LexScanner).

Supply method bodies in Tools API

Years ago, I wrote a code template that took a few simple parameters (points) and produced a class skeleton. Since some of the method bodies had code in them, I couldn't call InvokeClassCompletion and just placed the implementations with the declarations (user had to move them).
It has occurred to me that I can write a code template script engine to insert these methods in the correct position, but I don't see how I'm supposed to navigate the file. There are declarations for IOTAEditReader and IOTAEditWriter in ToolsAPI.pas, but I'm guessing there is a step missing - certainly I don't need to manually parse the Delphi code just to find the implementation section?
Does anyone have experience with it?
The IDE has plenty of parsers in it, but not one is made available for IDE plugins (ToolsAPI). So you have to write your own parser or use an existing one like http://delphiblog.twodesk.com/using-the-castalia-delphi-parser
You might find that GExperts or CNPack contains almost all the code you need, in one of its editor wizards.
If not, then, those two are the best reference I know for writing IDE plugins. As far as writing parsers, see Andreas' answer.
If you just want better code templates, you could consider buying Castalia, as it has an improved code template feature over the builtin delphi IDE plugin features. Castalia internally uses the Castalia delphi parser mentioned by andreas. It's quite good.

Need to create a compiled delphi app that can make a separate compiled app

I need to make an app that will let users select some options, click a button, and a separate compiled app is created. Is this possible? I am using delphi 7 and 2010.
Thanks for the replies. Here is a little more info.
It would have to be a graphical app and create a graphical app.
What I want is the user to fire up 'App A' (I originally made), be able to select some options (I apologize for the secrecy. I think this is a million dollar idea that probably 3 people may find useful :) then use the program to create 'App B.' 'App B' can then be distributed to end users and 'App B' is a single executable that includes a compiled app plus the configuration data. I don't care how, but I need 'App B' to be a single executable.
I wouldn't even need to use Delphi for the final compiled app. If there is some sort of "pseudo-compiler" that I can call from Delphi that would marry a precompiled exe and a separate config file into a single executable. That would work just fine as well.
Thank you for the replies and help.
Thank you.
I also faced a similar situation once. I had to produce an exe using my exe. I didn't want to go the compiling a source code because of complexity and license problems.
Lets call the parent app P and child app C. Also lets assume that whatever option C needs can be summed up in a config file (XML/INI etc). What I ended-up doing was:
Create P and C. Inserted C in resource data of P.
When user clicked the button after selecting options, P would extract C from its resource data.
Created an XML file containing the options selected by user and inserted it in C's resource data.
So whenever C will run, it will use the options given in the XML file stuffed in it. It looks like complicated and hacky but is reliable and simple. Do a google on "delphi embedding resource in exe" and you will find plenty of articles to do above.
It is possible. You will need a Delphi 7 (or compatible) compiler (command line at least) on the target machine. You will also need all the source code for the compiled application and that includes all the third party libraries if you use any.
When you have it all set just call the command line compiler (DCC32.EXE) with the proper parameters and paths.
You can use two approaches for this:
Call ShellExecute
Call CreateProcess
You will have more control over the execution with CreateProcess. Also you will have to watch out for legal issues and licences if you plan to use the compiler this way.
Given that the Delphi compiler can't be redistributed, one solution if the user has not a copy of Delphi may be to use a script engine (i.e. RemObjects PascalScript, but there are others), generate code for it, and embed that code (i.e. within a resource) in an executable that will execute it when launched.
Create a separate stub executable that implements all the logic you need, and that reads its configuration from its own local resources (look at the TResourceStream class to help you load a resource at runtime).
Include that stub executable as an RCDATA resource in your main app's resources when it is compiled.
At runtime, the main app can extract the stub executable from its resources when needed, save it to disk, and insert the necessary configuration data into the stub's resources using the Win32 API UpdateResource() function.
Without knowing more about why you think you need to do this, I assume you don't actually need to do this. Given the stated requirements, I'd simply have one app, written in Delphi, that looks for the existence of configuration data (.ini file, registry, etc..) In the absence of this, it presents a screen that "will let users select some options, click a button". Then the options are stored in a .ini file, and the rest of the program proceeds, making use of those options.
Alternately, I'd use some pascal scripting, such as provided by TMS.
If you are looking for a way to crank out custom-branded versions of an app, maybe use Inno Setup with a ResHacker step. i.e. gather requirements in Inno, spit out your .exe into a temp directory, use ResHacker to modify the .exe, copy it into the program folder.

Resources