Board index » delphi » TStringList in a dll

TStringList in a dll

I've created an exe and a dll, both using Delphi 1.0, and I want to
pass a TStringList object from the exe to the dll.  If I try to add a
string in the dll, it gives a GPF.  Has anyone done this before?  I
used code like:

dll code:

function MyFunction( MyList : TStringList ) : Boolean;
begin
        MyList.Add( 'Hello' );
end;

exe code:

var
        MyList : TStringList;
begin
        MyList := TStringList.Create;
        MyFunction( MyList );
end;

What is the correct way to do this?

Thanks for any help,
Brian
- Brian Duke
- Rivet Software
Before sending e-mail to me, please remove any ~'s in my
e-mail address that have been placed there to deter spam mail.

 

Re:TStringList in a dll


There must be a problem in the way that you are calling the .DLL,
as I've done this before with no problems...
Try putting the first line in MYFUNCTION so it says
"ShowMessage ('It worked');" and see if it executes before the GPF.

Quote
> I've created an exe and a dll, both using Delphi 1.0, and I want to
> pass a TStringList object from the exe to the dll.  If I try to add a
> string in the dll, it gives a GPF.  Has anyone done this before?  I
> used code like:

> dll code:

> function MyFunction( MyList : TStringList ) : Boolean;
> begin
>    MyList.Add( 'Hello' );
> end;
> exe code:

> var
>    MyList : TStringList;
> begin
>    MyList := TStringList.Create;
>    MyFunction( MyList );
> end;

> What is the correct way to do this?

Re:TStringList in a dll


I know it calls the dll ok, because it only crashes if I try to access
the TStringList object I'm passing.  I suspect it has something to do
with the segments.  The app and the dll have different data segments
and I suspect the TStringList is allocated from the apps data segment
rather than the stack segment.  Unfortunately, I'm not as proficient
in Delphi as I am in C and don't know how to remedy this problem.

Thanks for your help though,
Brian

Quote
>There must be a problem in the way that you are calling the .DLL,
>as I've done this before with no problems...
>Try putting the first line in MYFUNCTION so it says
>"ShowMessage ('It worked');" and see if it executes before the GPF.

>> I've created an exe and a dll, both using Delphi 1.0, and I want to
>> pass a TStringList object from the exe to the dll.  If I try to add a
>> string in the dll, it gives a GPF.  Has anyone done this before?  I
>> used code like:

>> dll code:

>> function MyFunction( MyList : TStringList ) : Boolean;
>> begin
>>        MyList.Add( 'Hello' );
>> end;

>> exe code:

>> var
>>        MyList : TStringList;
>> begin
>>        MyList := TStringList.Create;
>>        MyFunction( MyList );
>> end;

>> What is the correct way to do this?

- Brian Duke
- Rivet Software
Before sending e-mail to me, please remove any ~'s in my
e-mail address that have been placed there to deter spam mail.

Other Threads