Writing DLLs in Delphi
Setting up the Delphi Environment
I think it is important the DLLs I write can be called from any language. This basically means following the C style. (This is most important with strings, see later). Therefore I use Delphi as a prototyping tool for VB so I can do all the development and testing in Delphi. When I create the DLL and test from VB, I know the code is working OK.
Step 1: I create a Delphi project in the normal way, say rg.dpr. In this project I create a form and add buttons. Under the button.click event I put code to test the procedure being created. All the code to be included in the DLL is put into other units. Therefore, the smallest application has four files.
| rg.dpr. | the project file |
| rgtest.dfm | the form code |
| rgtest.pas | the unit file with the button click code |
| rg2.pas | the unit file(s) with the DLL code |
I then create another project, say rgdll.dpr, using the following method:
The new project file, with the changes shown, is below:
library Rgdll; {*1.program changed to library}
uses {*2.removed Forms }
Rg2 in 'RG2.PAS'; {$R *.RES}
exports {*3.add exports clause and the}
ChangeInt, {functions and procedures to export}
ChangeSingle;
begin {*4.remove code from main block}
end.
Therefore, the smallest DLL project has 2 files:
rgdll.dpr. the project file rg2.pas the unit file(s) with DLL code