PByteArray To OleVariant

Please discuss general Delphi programming topics here.

PByteArray To OleVariant

Postby akurawane » March 17th, 2014, 3:12 am

convert C++ to Delphi
C++
BYTE* savedMinData1 = new BYTE[FpLibXCapture.MinutiaeSize];
VARIANT varBuffer1;
varBuffer1.vt = VT_BYREF|VT_UI1;
varBuffer1.pbval = savedMinData1;
if (FpLibXCapture.LiveCapture(timeout, image_quality) == TRUE) {
if (FpLibXCapture.GetMinutiaeData(varBuffer1) == TRUE) {
// To do your code
}
}

Delphi
Const
register_quality = 50;
timeout = 6000;
Var
savedMinData1:PByteArray;
Buffer1: OleVariant;
begin
ReallocMemory(savedMinData1,FpLibXCapture1.MinutiaeSize);
TVariantArg(Buffer1).vt := VT_BYREF or VT_UI1;
TVariantArg(Buffer1).pbVal := Pointer(savedMinData1);

if (FpLibXCapture.LiveCapture(timeout, image_quality) = TRUE) then
if (FpLibXCapture.GetMinutiaeData(Buffer1) = TRUE) then
ShowMessage('OK')
else
ShowMessage('KO');
end;

question : why FpLibXCapture.GetMinutiaeData(Buffer1) value is FALSE or buffer1 value IS NULL ?
thax
akurawane
Member
Member
 
Posts: 1
Joined: July 3rd, 2012, 4:54 am

Re: PByteArray To OleVariant

Postby Kambiz » March 29th, 2014, 9:06 pm

The following function creates a variant from an array of bytes:
Code: Select all
function BytesToVariant(bytes: array of Byte): Variant;
var
  buffer: Pointer;
begin
  Result := VarArrayCreate([0, Length(bytes)-1], varByte);
  buffer := varArrayLock(Result);
  Move(bytes[0], buffer^, Length(bytes));
  VarArrayUnlock(Result);
end;

Then you can go this way:
Code: Select all
var
  bytes: array of Byte;
begin
  SetLength(bytes, FpLibXCapture.MinutiaeSize);
  if FpLibXCapture.LiveCapture(timeout, image_quality) then
  begin
    if FpLibXCapture.GetMinutiaeData(BytesToVariant(bytes)) then
    begin
      // do the rest
    end;
  end;
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron