Search code examples
delphiautomationdelphi-7fingerprintdelphi-6

IDispatch vs OleVariant


I got a sample code from fingerprint SDK for event onDone (after registering a fingerprint)

procedure TfrmRegister.FPRegisterTemplate1Done(ASender: TObject;
var pTemplate: OleVariant);
var
  l_val : OleVariant;  
  l_pArray : PSafeArray;
  i : integer;
  fpBuffer : PByteArray;
begin
  txtEvtMessage.Caption := 'Done Event Received !!';
  pTemplate.Export(l_val);
  l_pArray := PSafeArray(TVarData(l_val).VArray);
  blobSize := l_pArray.rgsabound[0].cElements * l_pArray.cbElements;
  fpBuffer := VarArrayLock(l_val);

  for i := 0 to blobSize - 1 do
  fpData[i] := fpBuffer[i]; //pvData is byte array

  VarArrayUnlock(l_val);
  mode := 0;
  btnVerify.Enabled := True;
end;

But when I install the SDK and import the type library the second parameter of onDone is const pTemplate:IDispatch not var pTemplate:OleVariant

So an error comes in line pTemplate.Export(l_val); as 'Undeclared identifier: 'Export'

I don't understand about ActiveX/OLE/COM programming at all. Seems it likes old pascal code (PSafeArray,PByteArray,etc) and very hard to understand this term with easy example and explanation.

Anybody know how to make these codes run correctly with some modifications? Actually these codes for Delphi 6 (I'm using Delphi 7)

Thank you


Solution

  • If the type library says the parameter is an IDispatch, then it is really an IDispatch. Simply assign it to a local OleVariant variable and then use that as needed, eg:

    procedure TfrmRegister.FPRegisterTemplate1Done(ASender: TObject;
      const pTemplate: IDispatch);
    var
      l_template, l_val : OleVariant;  
      l_pArray : PSafeArray;
      i : integer;
      fpBuffer : PByteArray;
    begin
      txtEvtMessage.Caption := 'Done Event Received !!';
    
      l_template := pTemplate;
      l_template.Export(l_val);
    
      l_pArray := PSafeArray(TVarData(l_val).VArray);
      blobSize := l_pArray.rgsabound[0].cElements * l_pArray.cbElements;
      fpBuffer := VarArrayLock(l_val);
    
      for i := 0 to blobSize - 1 do
        fpData[i] := fpBuffer[i]; //pvData is byte array
    
      VarArrayUnlock(l_val);
      mode := 0;
      btnVerify.Enabled := True;
    end;