皆さんこんにちは。
お知恵を拝借できましたら幸いです。
只今VBの構造体をDelphiで作成したDLLへ渡しています。
VB:'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Type TRecData
intX As Long
intY As Long
arrint(31) As Long
strS As String
End Type
Public Declare Function OpenDllForm Lib "arrDelTest.dll" (RecData As TRecData) As Boolean
Private Sub Command1_Click()
Dim RecD As TRecData
Dim i As Integer
For i = 0 To 31
RecD.intBui(i) = i
Next
RecD.intX = CLng(Text1.Text)
RecD.intY = CLng(Text2.Text)
RecD.strS = Text3.Text
RecD.dDate = Date
If OpenDllForm(RecD) = False Then
End If
End Sub
Delphi://///////////////////////////////////////////////////////////
type
TRecData = record
FIntX :Integer;
FIntY :Integer;
FarrInt :array [0..31] of Integer;
FStrS :PChar;
end;
//===========(略)
var
frmArrDll: TfrmArrDll;
function OpenDllForm(var RecData:TRecData):Boolean; stdcall;
implementation
var
RecD :TRecData;
{$R *.dfm}
function OpenDllForm(var RecData:TRecData):Boolean; stdcall;
begin
frmArrDll := TfrmArrDll.Create(Application);
try
RecD := RecData;
if frmArrDll.ShowModal = mrOk then
begin
end;
finally
frmArrDll.Free;
end;
end;
end.
以上で、VBの構造体をDelphiのRecord型に渡す事までは出来たのですが
問題は、これを動的配列で渡したいのですがうまくいきません。
VBでは、上記の構造体に対して
Public Declare Function OpenArrayForm Lib "arrDelTest.dll" (arrData() As TRecData) As Boolean
Private Sub Command2_Click()
Dim arrData() As TRecData
ReDim arrData(3)
’(略)
If OpenArrayForm(arrData()) = True Then
End If
End Sub
で、渡せるとあるのですが。
Delphi側でどうしたら良いのかさっぱり判りません。
まる投げのようで申し訳ないのですが、何かヒントでも頂ければありがたく思います。
一部間違い
Private Sub Command1_Click()
Dim RecD As TRecData
Dim i As Integer
For i = 0 To 31
RecD.arrint(i) = i
Next
RecD.intX = CLng(Text1.Text)
RecD.intY = CLng(Text2.Text)
RecD.strS = Text3.Text
RecD.dDate = Date
If OpenDllForm(RecD) = False Then
End If
End Sub
です。
VBはチョートウシロウなのですが、OpenArrayForm(arrData())のパラメータは、配列の先頭アドレスでしょうか? もしもそうでなければ配列の先頭アドレス同士(いわゆるポインタ)の受け渡しであれば間違いないように思う昨日明日。
ブランク・ゼロさんありがとうございます。
どうも、すいません。
上記の方法は間違いでした。
配列の先頭アドレス同士ですね。
「配列が格納されているメモリ領域の先頭アドレスを指定しなければならない」
とありました。
Public Declare Function OpenArrayForm Lib "arrDelTest.dll" (arrData As TRecData) As Boolean
Private Sub Command2_Click()
Dim arrData() As TRecData
ReDim arrData(3)
’(略)
If OpenArrayForm(arrData(0)) = True Then
End If
End Sub
として、配列の先頭アドレスを渡す事ができます。
ツイート | ![]() |