translate NEW from DELPHI to VB

I have to traslate this function from Delphi to VB, but I don't know how to use to alloc dinamically the memory for LPLINEDEVCAPS. Here is the code :

    dwDeviceID: DWORD;
    dwAPIVersion: DWORD;
    lpLineDevCaps_: LPLINEDEVCAPS;
    sLineName: string;

    lpLineDevCaps_ := nil;
    GetMem(LPVOID(lpLineDevCaps_), sizeof(TLINEDEVCAPS) + 1024);
    ZeroMem (PChar(lpLineDevCaps_)); //fill with zero's
    lpLineDevCaps_^.dwTotalSize:=sizeof(TLINEDEVCAPS) + 1024;


    if (lpLineDevCaps_ <> nil) then
        freemem (lpLineDevCaps_);

Who is Participating?
stefanxConnect With a Mentor Commented:
New in Delphi creates a dynamically allocated space in memory and returns a pointer to it. As far as I know, there is no direct analog for this in VB. Nevertheless, you can do this by creating a dynamic array of type LPLINEDEVCAPS (which you'll have to define as a Visual Basic Type). I don't know what lpLineDevCaps looks like in your Delphi project, bur basically you'd do something like the following (in a VB code module):

Type lpLineDevCaps
  Field1 As Integer
  Field2 As Long
  Field3 AS String
End Type

Public L() As lpLineDevCaps
Public Elements As Long

The Type definition declares what lpLineDevCaps should look like. The dynamic array is L(), while the long variable Elements tells you how many elements are in the array.

When you need to assign a variable dynamically now, use the following code :

Elements = Elements + 1
If Elements = 1 Then Redim L(1) Else Redim Preserve L(Elements)
' Fill in your values
L(Elements).Field1 = 1
L(Elements).Field2 = 22&
L(Elements).Field3 = "This is it"

Once you are done, you can get rid of the dynamic memory by saying

Erase L

Hope that helps you.

All Courses

From novice to tech pro — start learning today.