VB 소스를 델파이로 작성하려고 합니다.
-- VB소스
Public Function AddOPCItems() As Boolean
Dim arItemIDs() As String
Dim arClientHandles() As Long
Dim arServerHandles() As Long
Dim arErrors() As Long
Dim i As Long
Dim lIndex As Long
On Error GoTo ErrorHandler
'/* For this example, remove existing OPC items if they exist
If MyOPCGroup.OPCItems.Count Then
MyOPCGroup.IsActive = False
Call RemoveOPCItems
End If
'/* Redim arrays to maximum possible size
ReDim arItemIDs(1 To 4)
ReDim arClientHandles(1 To 4)
'/* Build up ItemID definitions by combining Topic and Item (e.g. "[MyTopic]N10:0")
For i = 0 To 3
If Len(txtTopic(i)) > 0 And Len(txtItem(i)) > 0 Then
lIndex = lIndex + 1
'/* Build array of itemIDs by combining Topic and Item specification
arItemIDs(lIndex) = "[" & txtTopic(i) & "]" & txtItem(i)
arClientHandles(lIndex) = i
End If
Next 'i
If lIndex Then
'/* Redim arrays to correct size based on items defined
ReDim Preserve arItemIDs(1 To lIndex)
ReDim Preserve arClientHandles(1 To lIndex)
'/* Add items to OPCGroup
MyOPCGroup.OPCItems.AddItems lIndex, arItemIDs, arClientHandles, arServerHandles, arErrors
'/* Check for errors
For i = LBound(arErrors) To UBound(arErrors)
Call DisplayErrorString(arErrors(i))
Next 'i
If MyOPCGroup.OPCItems.Count Then
'/* Return TRUE if items added successfully
AddOPCItems = True
End If
Else
txtStatus = "No valid item definitions to add."
End If
Exit Function
ErrorHandler:
PostMessage Err.Number
End Function
--------------------------------------------------------------
MyOPCGroup.OPCItems.AddItems lIndex, arItemIDs, arClientHandles, arServerHandles, arErrors 부분을
델파이에서 작성하려는데 VB에서는 형식이 다음과 같이 선언되어 있습니다.
Sub AddItems(NumItems As Long, ItemIDs() As String, ClientHandles() As Long, ServerHandles() As Long, Errors() As Long, [RequestedDataTypes], [AccessPaths])
그런데 델파이에 import한 파일에서 찾아보면 함수의 매개변수가 pSafeArray타입으로 선언되어 있어 이걸 어떤방식으로 사용해야할지 모르겠습니다. arItemIDs, arClientHandles 각각 스트링과 integer 배열인데
델파이에서 배열을 pSafeArray타입으로 변환해서 넘겨야하는데 어떻게 해야될지 모르겠습니다.
델파이에 선언된 내용입니다.
-------------------------------------------------
-- RsiOPCAuto_TLB.pas
-------------------------------------------------
procedure AddItems(NumItems: Integer; var ItemIDs: PSafeArray; var ClientHandles: PSafeArray; out ServerHandles: PSafeArray; out Errors: PSafeArray; RequestedDataTypes: OleVariant; AccessPaths: OleVariant); safecall;
-------------------------------------------------
-- ActiveX.pas
-------------------------------------------------
PSafeArray = ^TSafeArray;
{$EXTERNALSYM tagSAFEARRAY}
tagSAFEARRAY = record
cDims: Word;
fFeatures: Word;
cbElements: Longint;
cLocks: Longint;
pvData: Pointer;
rgsabound: array[0..0] of TSafeArrayBound;
end;
TSafeArray = tagSAFEARRAY;
{$EXTERNALSYM SAFEARRAY}
SAFEARRAY = TSafeArray;
pSafeArray를 어떤 방식으로 사용해야 하는지 알려주세요.