View Full Version : "Scripting"

04-02-2004, 09:40 PM
Hi guys!

I want to create a very very basic scripting system, all I want to do, is to run procedures/functions with parameters from a file at runtime.

IE: the following line in a text file would execute "procedure Test(X: integer);" in the main app.


The thing is, I have no idea what-so-ever when it comes to how to actually do somthing like this. So I'm just fishing around for some tips ;)

Harry Hunt
04-02-2004, 10:15 PM
I don't think you need to take the usual approach at writing a scripting system as what you want to do isn't really executing expressions and stuff like that.

If you say that all procedure calls have this format:
then all you have to do is go through each line of your text file, and parse it. So you'd copy from the beginning of a line up to the first opening bracket (this gives you the name of the procedure), then you'd move on up to the first comma and you'd have the first parameter, etc.

Now calling procedures in your main program is a whole different matter. I'd recommend encapsulating the parser into an object. The object could have an event that gets called for each procedure call in your text file. So the procedure handling that event could then call the procedures in your main program.
You can also create a list/array of procedures like this:

type TMyProcedure = procedure(Param1: ParamType; Param2: ParamType2...);

type TMyProcedureItem = record
Proc: TMyProcedure;
Name: string;

MyProcedures: array[1..10] of TMyProcedureItem;

It's all up to you. But it should be easy enough to write.
Hope that helped.

04-02-2004, 10:52 PM
If your functions are methods of a class, rather than free-standing ones, you could look at TObject.MethodAddress (http://www.delphi3d.net/articles/viewarticle.php?article=console.htm)

04-02-2004, 11:29 PM
Thank you to the both of you for the extremly quick replies ;)

I've written some very nasty test code based on the ideas I got from reading Harry's post and the article at Delphi3D. :)

Again, thanks guys :)

05-02-2004, 04:16 AM
Also DWS at its most simple is exactly what you want to do.

05-02-2004, 05:06 PM
cairnswm: I tried it out yesterday, (found a link when searching the forums) but I wanted somthing non-vcl ;)

08-02-2004, 03:45 PM
[quote="Mrwb"]cairnswm: I tried it out yesterday, (found a ]
There is ifps3. It doesnt even use Borland's classes unit to my knowlage.

link (http://www.carlo-kok.com/ifps3.php)

08-02-2004, 06:36 PM
ggs: thanks, looks very neat, I'll check it out later :)