parameter by reference in ActiveX component

parameter by reference in ActiveX component

I am currently using an ActiveX component and have problems with the parameter by reference of the function of this component.

The definition of the function is:

HRESULT ReadInformation ([in] BSTR * szCard, [in] int iTimeChip, [in] int iTimeMag, [in] int iType, [in] BSTR messMag, [out, retval] int * rc)

Defining a procedure in a normal way that makes use of the function I got the following error: "Access violations at address 1381O7AO in module * .DLL. Write of address 00000000"

procedure TForm2.btnConInfClick (Sender: TObject);
var
....
CardInformation: WideString;
begin
try
...
ReadCardResult: = MyCompActX.ReadInformation (CardInformation, 20, 20, 1, 'ENTER NUM ...');
if Trim (CardInformation) <> '' then
ShowMessage (CardInformation);
finally
MyCompActX.Free;
end;
end;

Then doing some research and suggestions from some friends they indicated that I had to use pointers with dynamic memory and I arrived at the following solution:

procedure TForm2.btnConInfClick (Sender: TObject);
var
CardInformation: ^ WideString;
CardInformation2: WideString;
begin
try
...
try
GetMem (CardInformation, 255 * 2);
ReadCardResult: = MyCompActX.ReadInformation (CardInformation ^, 20, 20, 1, 'ENTER NUM ...');
CardInformation2: = PWideChar (CardInformation ^);
finally
FreeMem (CardInformation);
end;
if Trim (CardInformation2) <> '' then
ShowMessage (CardInformation2);
finally
MyCompActX.Free;
end;
end;

The problem I have and the questions are as follows:

1. The solution works for me in a recent version of Delphi (Delphi Tokyo), when I try to do the same thing in a Delphi 6 version it is generating an error when casting the pointer (CardInformation2: = PWideChar (CardInformation ^);), ERROR: "invalid pointer operation" can you help me identify where the problem is?

2. Capable with the experience of a friend of the forum, able there is another way to get the result of the function? or is there another way to consume the function with dynamic memory? able the way to cast the pointer in Delphi 6 does not support it?

Thank you very much for your comments and I hope you can help me with your suggestions.

Comments