Hallo,
hoffentlich kann mir jemand helfen!
Folgendes:
Ich habe ein Hauptprogramm mit einem nicht initialisierten offenen Array. Dieses Array soll an eine DLL übergeben werden (als Pointer), die es initialisiert und füllt.
Nach dem verlassen der DLL soll ein Zugriff vom Hauptprogramm auf dieses gefüllte Array möglich sein.
Mein Test:
<B>Hauptprogramm</B>
<PRE>unit Host_Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function FillArray(AdrArray: LongInt): Boolean; stdcall;
external 'Pointertest.dll';
procedure TForm1.Button1Click(Sender: TObject);
type
pArray= ^harray;
hArray= array of integer;
var
PtrArr: pArray;
mArray: harray;
x : integer;
begin
PtrArr:=@mArray;
label1.Caption:=InttoStr(LongInt(PtrArr));
if (FillArray(LongInt(PtrArr))) then
for x:= Low(mArray) to High(mArray) do
begin
Label1.Caption:= Label1.Caption+';'+IntToStr(mArray[x]);
end;
end;
end.</PRE>
<B>DLL</B>
<PRE>library PointerTest;
uses
SysUtils, Classes, Windows;
function FillArray(AdrArray: LongInt): boolean; stdcall;
type
pArray= ^harray;
hArray= array of integer;
var
PtrArrArray;
x: integer;
begin
result:=false;
PtrArr:=Ptr(AdrArray);
SetLength(PtrArr^, 10);
for x:=Low(PtrArr^) to High(PtrArr^) do PtrArr^[x]:=x+20;
result:=true;
end;
exports
FillArray;</PRE>
Danke.
hoffentlich kann mir jemand helfen!
Folgendes:
Ich habe ein Hauptprogramm mit einem nicht initialisierten offenen Array. Dieses Array soll an eine DLL übergeben werden (als Pointer), die es initialisiert und füllt.
Nach dem verlassen der DLL soll ein Zugriff vom Hauptprogramm auf dieses gefüllte Array möglich sein.
Mein Test:
<B>Hauptprogramm</B>
<PRE>unit Host_Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function FillArray(AdrArray: LongInt): Boolean; stdcall;
external 'Pointertest.dll';
procedure TForm1.Button1Click(Sender: TObject);
type
pArray= ^harray;
hArray= array of integer;
var
PtrArr: pArray;
mArray: harray;
x : integer;
begin
PtrArr:=@mArray;
label1.Caption:=InttoStr(LongInt(PtrArr));
if (FillArray(LongInt(PtrArr))) then
for x:= Low(mArray) to High(mArray) do
begin
Label1.Caption:= Label1.Caption+';'+IntToStr(mArray[x]);
end;
end;
end.</PRE>
<B>DLL</B>
<PRE>library PointerTest;
uses
SysUtils, Classes, Windows;
function FillArray(AdrArray: LongInt): boolean; stdcall;
type
pArray= ^harray;
hArray= array of integer;
var
PtrArrArray;
x: integer;
begin
result:=false;
PtrArr:=Ptr(AdrArray);
SetLength(PtrArr^, 10);
for x:=Low(PtrArr^) to High(PtrArr^) do PtrArr^[x]:=x+20;
result:=true;
end;
exports
FillArray;</PRE>
Danke.