I have a form in my DLL. The form should return a TStringlist with values
in it.
How do I get the TStringlist back to the calling application?
Is it perhabs possible by sending the Stringlist as a parameter in the
function call?
Bye
--
Kolbeinn Sigurjónsson
_______________
Net-Album.net
k...@net-album.net
www.net-album.net
s: 570-7166
Hi
You know:
1. If you let the function return an object as the result the DLL is going
to be compiler and Language depended!
2.Ok so your pretty sure that the DLL is only going to be used in your
app...
Here is an example:
Procedure GetAllValues(Var ValueString : TStringList); stdcall; external
'PWGlobal.dll';
Cheers Wayne
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
On 1/26/00, 2:07:41 AM, "Kolbeinn Sigurjonsson" <k...@net-album.com> wrote
regarding Can a DLL return a TStringlist?:
> Hi!
> I have a form in my DLL. The form should return a TStringlist with
values
> in it.
> How do I get the TStringlist back to the calling application?
> Is it perhabs possible by sending the Stringlist as a parameter in the
> function call?
Tstringlist is Delphi dependant, but you could return the Text
property of your string list and document the fact that this function
returns a CRLF deliminated string. This way a delphi user can populate
a Tstringlist by:
MyStringList.Text := YourFuntion;
and a non-delphi user can do whatever manipulations are needed to
parse the returned string into a native string list.
HTH
This is a reply I posted to someone else yesterday, Kolbeinn. It happens to
fit your case to a T --
PhR
--------------------
<<Robin:
How do I call a dll from within a delphi unit (using Delphi 4)? How do I
pass info to the dll? If there is something on the web written about
this please point me in the right direction. Thanks.
>>
Here's a full example, dll and caller, below. You'll note that the caller's
.dpr's Uses list begins with sharemem, and so does the dll's. This is
necessary for passing strings back and forth. Or dynamic arrays. Otherwise
(except in bizarre cases), it's not needed.
You'll note also that both the caller and the dll specify "stdcall". This is
for example's sake. If you don't specify anything, the call format is
register, and the dll can only be called from Delphi -- which would be the
case anyhow if it uses ansiStrings (unless you have BCB, Delphi's C++
sister). If you do specify a call format, as I do in the example, you must
absolutely specify it on both sides, and there's seldom any reason to
specify any other than stdcall.
If your dll does not need sharemem, does not use classes from the VCL, like
TstringList, and uses stdcall, it can be called from anything, even a Word
macro.
Do read the Help on Dlls.
PhR
--- Dll code ---------------------------
Library myDll;
Uses sharemem, sysUtils, classes;
Procedure fillList(sls: TstringList); stdcall;
Var
n: integer;
Begin
for n := 1 to 12 do sls.add(longMonthNames[n]);
End;
Exports
fillList;
End.
--------------------------
--- Caller code --------------------
Program dllCall;
Uses sharemem, classes, dialogs;
Procedure fillList(sls: TstringList); stdCall; external 'myDll.dll';
Procedure test;
Var
sls: TstringList;
Begin
sls := TstringList.create;
fillList(sls);
showMessage(sls.text);
sls.free;
End;
Begin
test;
End.
--------------------------------