1

Is there a way to use dwscript as a plugin framework for a Delphi app? Eg I have a simple method in dwscript that adds to numbers and this needs to be called from the hosting application.

One solution is to leave the dwscript as a text file and load the text file at runtime and call the method from the host. Is there way to create a dll that contains the dwscript and load the dll at runtime and then call the method?

rhody
  • 2,274
  • 2
  • 22
  • 40

2 Answers2

2

DWS does not create DLLs. It compiles a pascal style source to an intermediate file for execution so you can deploy the text file as a plug in if you wish. For an example of calling back into your DWS source download and run the IDE demo in the tools directory of the DWS site, this has an 'execute procedure' menu option and simple source to see how it's done.

Brian Frost
  • 13,334
  • 11
  • 80
  • 154
1

There should be no problem, but you should take a look first how to manage dll plugins inside delphi, becaus ethere are some restrictions:

Check delphi.about.com there are some tutorials. http://delphi.about.com/od/windowsshellapi/a/dll_basics.htm

One of the issues you will find first is that you could have problems with classes, because a DLL its like an independent application so it creates its own Class table. So for the host app the class TDWScript contained in the dll its a different class that the one it has contained (the host).

There are some ways you can acomplish that and that depends what are your needs:

1) You could for example call DLL methods, not directly calling the TDWscript class, just calling a method like 'ExecuteScript( afilename )'

2) If your plugin need to interact with the host application it is mroe complex, because you have to stablish a communication protocol so both (host and plugin could interact)

The options are: a) Use Interfaces instead of classes directly. b) Use a memory manager like sharemem (wich comes with delphi) or fastMM4 (open source) which should be included in bot DLL and APP so they will share the same memory manager and so the same class table.

If you're new to plugins please check JEDI VCl components there they have a JvPlugin and JvPluginManager, its a simple but powerfull Framework to start cretaing your own Plugin framework. There are some demos of how to manage plugins, create them using the DLL way. Which could be usefull for what you want. and also a demo of how you can use Interfaces instead of direct using the classes.

fduenas
  • 305
  • 3
  • 6