您正在使用一款已经过时的浏览器!部分功能不能正常使用。
请尝试升级或使用
其他浏览器。
delphi 与 VB 的variant数据类型一样吗? ( 积分: 200 )
dongruxue
Unregistered / Unconfirmed
GUEST, unregistred user!
一个C做的DLL,VB能正常调用,但是转为DELPHI后不能正常调用,其中有一个参数是VARIANT类型的,并且是按地址传递的,请高手帮忙
Buddy.Sun
Unregistered / Unconfirmed
GUEST, unregistred user!
把VB的声明贴出来吧,是使用的BYVAL么?那么在D中恐怕的使用指针而非VARIANT了
东兰梦舞
Unregistered / Unconfirmed
GUEST, unregistred user!
VB的variant对应于DELPHI的olevariant。
dongruxue
Unregistered / Unconfirmed
GUEST, unregistred user!
VB的结构:<br>Type param_byname_data<br> point_name As String<br> param_name As String<br> param_offset As Long<br> padding1 As Long 'for byte alignment between VB and C<br> param_value As Variant<br> param_type As Integer<br> padding2 As Integer 'for byte alignment between VB and C<br> status As Long<br>End Type<br>声明:<br>Public Declare Function rhsc_param_value_bynames Lib "hscnetapi.dll" _<br> Alias "rhsc_param_value_bynames_vb" _<br> (ByVal Server As String, ByVal period As Long, ByVal num_requests As Long, _<br> param_byname_data_array() As param_byname_data) As Long<br><br>调用示例:<br>'Set up local variables<br> Dim data() As param_byname_data<br> Dim Count As Integer<br> Dim i As Integer<br> Dim status As Long<br> Dim period As Long<br> Dim NameArray As Variant<br> <br>'Start routine<br> NameArray = ArraysFromString(EdtGetName, 3, Count)<br> If Count < 1 Then Exit Sub<br> ReDim data(Count)<br> For i = 0 To Count - 1<br> data(i).point_name = NameArray(0, i)<br> data(i).param_name = NameArray(1, i)<br> If Not IsNumeric(NameArray(2, i)) Then<br> MsgBox ("Parameter Offset " & i + 1 & " must be a numeric expression."
<br> Exit Sub<br> End If<br> data(i).param_offset = CLng(NameArray(2, i))<br> Next 'i<br> <br> period = GetPeriod()<br> <br> status = rhsc_param_value_bynames(EdtHostName, period, Count, data)
dongruxue
Unregistered / Unconfirmed
GUEST, unregistred user!
改为delphi:<br> Type<br> Pparam_byname_data = ^param_byname_data;<br> param_byname_data = packed record<br> point_name : string ;<br> param_name : string ;<br> param_offset : LongInt ;<br> padding1 : LongInt ; //for byte alignment between VB and C<br> param_value : OLEVariant;<br> param_type : word;<br> padding2 : word ; //for byte alignment between VB and C<br> status : LongInt ;<br> End; {param_byname_data}<br><br><br><br> function rhsc_param_value_bynames(const Server:string;const period:integer; const num_requests:Integer;<br> var param_byname_data_array:array of param_byname_data):integer;stdcall ;<br> external 'hscnetapi.dll' name 'rhsc_param_value_bynames_vb';<br><br>调用示例 <br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> I:integer;<br> servername: array[0..255] of char;<br> // params: Tparam_byname_data;<br> A: array of param_byname_data;<br><br>begin<br> servername:='localhost';<br> // params:= VarArrayCreate([0, 4],Tparam_byname_data);<br><br> // A := VarArrayCreate([0,1], varVariant);<br><br> setlength(A,1);<br><br><br> // for i:=0 to 2 do<br> // begin<br> A[0].point_name :='TR-OUT';<br> A[0].param_name :='PV';<br> A[0].param_offset:=1;<br> // params
.padding1 :=1;<br> // params.param_value :=1;<br> // params.param_type :=2;<br> // params.padding2 :=1;<br> // params.status :=1;<br> // end;<br><br><br><br><br><br> listbox1.Items.Add(inttostr(rhsc_param_value_bynames('localhost',0,1,A)));<br> listbox1.Items.Add(a[0].point_name <br> listbox1.Items.Add(a[0].param_value <br>end;