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 :

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

    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_);

End;
gianlucaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stefanxCommented:
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.




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.