Return string array from a delphi dll
up vote
-1
down vote
favorite
I want to return string array from a delphi dll to delphi application. This is what i tried. But it gives Invalid pointer operation error.
dll code
type
TStringArray = array of string;
function GetDataArray(): TStringArray; stdcall;
var D: TnxQuery;
begin
form1 := TForm1.Create(nil);
result := form1.GetData;
end;
function TForm1.GetData: TStringArray;
begin
SetLength(result, 2);
result[0] := 'AAA';
result[1] := 'BBB';
end;
Delphi application code
function GetDataArray(): TStringArray; stdcall; external 'Nx2Con.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDataArray;
end;
delphi dll delphi-xe2 delphi-2010
add a comment |
up vote
-1
down vote
favorite
I want to return string array from a delphi dll to delphi application. This is what i tried. But it gives Invalid pointer operation error.
dll code
type
TStringArray = array of string;
function GetDataArray(): TStringArray; stdcall;
var D: TnxQuery;
begin
form1 := TForm1.Create(nil);
result := form1.GetData;
end;
function TForm1.GetData: TStringArray;
begin
SetLength(result, 2);
result[0] := 'AAA';
result[1] := 'BBB';
end;
Delphi application code
function GetDataArray(): TStringArray; stdcall; external 'Nx2Con.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDataArray;
end;
delphi dll delphi-xe2 delphi-2010
3
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I want to return string array from a delphi dll to delphi application. This is what i tried. But it gives Invalid pointer operation error.
dll code
type
TStringArray = array of string;
function GetDataArray(): TStringArray; stdcall;
var D: TnxQuery;
begin
form1 := TForm1.Create(nil);
result := form1.GetData;
end;
function TForm1.GetData: TStringArray;
begin
SetLength(result, 2);
result[0] := 'AAA';
result[1] := 'BBB';
end;
Delphi application code
function GetDataArray(): TStringArray; stdcall; external 'Nx2Con.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDataArray;
end;
delphi dll delphi-xe2 delphi-2010
I want to return string array from a delphi dll to delphi application. This is what i tried. But it gives Invalid pointer operation error.
dll code
type
TStringArray = array of string;
function GetDataArray(): TStringArray; stdcall;
var D: TnxQuery;
begin
form1 := TForm1.Create(nil);
result := form1.GetData;
end;
function TForm1.GetData: TStringArray;
begin
SetLength(result, 2);
result[0] := 'AAA';
result[1] := 'BBB';
end;
Delphi application code
function GetDataArray(): TStringArray; stdcall; external 'Nx2Con.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
GetDataArray;
end;
delphi dll delphi-xe2 delphi-2010
delphi dll delphi-xe2 delphi-2010
asked Nov 20 at 5:54
Danush
344
344
3
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15
add a comment |
3
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15
3
3
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387022%2freturn-string-array-from-a-delphi-dll%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Memory is allocated in one module and then destroyed in another. A well known problem. You can use a shared memory manager, or have the caller allocate the memory, or indeed there are other approaches.
– David Heffernan
Nov 20 at 6:17
Please do yourself a favour and thoroughly read my article about DLL dos and don'ts. You can pass back strings and arrays of strings from DLLs, but most definitely not the way you do it. And if this is a DLL to be used by Delphi and/or C++Builder only, consider using packages instead.
– Rudy Velthuis
Nov 20 at 7:03
If you make reading your questions easier, you will likely get more answers. In this case: Please indent your source code.
– dummzeuch
Nov 20 at 10:15