This example shows you how to manipulate components which exist on a form calling your DLL
1) Depending on the version of Delphi that you have, click File -> New -> DLL
2) Once that has loaded up... you should have something which looks like this :
---------------------------------------
library Project1;
uses
SysUtils,
Classes;
{$R *.res}
begin
end.
---------------------------------------
ok, the main part you need to know is that you cannot directly relate to
components on your form linking to your app in the uses clause... you have to
create a virtual Button or component until you can link it to the destination
app.
Ill show you what i mean by this example:
---------------------------------------
library Project1;
uses
SysUtils,
Classes,
StdCtrls;
{$R *.res}
procedure AddItemToListBox(MyListBox : TListBox);
begin
MyListBox.Items.Add('hello world');
end;
exports
AddItemToListBox;
end.
---------------------------------------
You need the StdCtrls in the uses clause because this is where the components
resides in its source file... if you want to have a virtual DBGrid or something
like that or a component which doesnt reside in the StdCtrls then you should
find the right source file which does... these files can be found in the
\delphi\source\vcl\ directories...
<Note> You must always remember to add your created procedure to the exports
list... this is so your application can call upon your proc() from within the
DLL otherwise it will stay hidden.
Now you have that DLL you can start on your app that will call the procedure
from your DLL
1) Start a new app
2) Add a listbox
3) At the part where is lists something like this :
---------------------------------------
{$R *.dfm}
---------------------------------------
write this:
---------------------------------------
{$R *.dfm}
procedure AddItemToListBox(MyListBox : TListBox);stdcall; external
'YOURDLL.DLL';
---------------------------------------
basically to summarize that... it is a standard call because, well... i dont
actually know... but it is, so believe me and it is external because it is
calling the DLL File... you have to place the DLL in your app's search path in
your project options -> Directories...
Next thing is to make the call, make an TForm1OnCreate procedure from your
object inspector and in there put this...
---------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
AddItemToListBox(ListBox1);
end;
---------------------------------------
Run the app now and as long as you have the DLL where you app can find it...
i.e. in the same directory or in the search path and you have all the names
correct then it will add the item "hello world" to your listbox from your DLL...
thats basically giving you a simplistic intro to DLLs, i think the rest is self-explanitory...
if you need anymore help concerning this or anything else (providing that i can
help you with it) email me
Tronied