I wrote a library like this
library library_delegate;
uses Classes, SysUtils;
type commandevent=procedure (text:string);
var ocommand:commandevent;
procedure create(cmd:commandevent);stdcall;
begin
ocommand:=cmd;
end;
procedure writetext(text:string);stdcall;
begin
if assigned(ocommand) then
ocommand(text);
end;
exports create,writetext;
begin
end.
then compiled it to "library_delegate.dll"
after that I wrote a program
program use_library_delegate;
uses Classes, SysUtils;
type commandevent=procedure (text:string);
procedure create(cmd:commandevent);stdcall;external 'library_delegate';
procedure writetext(text:string);stdcall;external 'library_delegate';
procedure writeatext(text:string);
begin
writeln(text);
end;
var i:integer;
begin
create(@writeatext);
for i:=1 to 100 do
writetext('Text line '+inttostr(i));
readln;
end.
the program run as I expected, it wrote 100 text line to the console
I want to know if this dll could be used in visual basic or C(or other windows programming language). And I am curious to know how simple it is to use the dll's function in those language (especially at passing the procedure type parameter in the "create" procedure), can you give me any examples.
another question, can we assign or read the "ocommand" directly from the program?