-1

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

FZS
  • 160
  • 1
  • 2
  • 14
  • That's not old code. That's just COM. Why not try to learn and understand. – David Heffernan Oct 12 '16 at 04:17
  • @DavidHeffernan do you have link/articles about COM with easy example and easy explanation (simple english, not programming english) ? I can't found it, most of them are to complicated to follow. AFAIK, not all beginner programming understand about COM programming easily – FZS Oct 12 '16 at 04:29
  • Some things are just hard. If you don't understand COM then no simple tutorial will change that in 2 minutes. Some things take effort. – David Heffernan Oct 12 '16 at 04:31
  • 1
    @DavidHeffernan, of course some things are just hard and will not understand in just 2 minutes. But without good explanations and good examples that's makes all looks impossible to understand. Not all programmer are smart and genius. And I'm not try to create a COM here, let the manufacture take care of it, I just want to try to modified the code. – FZS Oct 12 '16 at 04:43

2 Answers2

4

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
3

If you say you were able to import the type library, you should be able to find which interface actually describes this Export method. If, then, you say this OnDone event handler has IDispatch where was OleVariant before, you should be able to replace this late-bound call of Export into an early-bound call. If this interface is called IExporter for example (to be sure you would have to share this *_TLB.pas file with us or look it up in the documentation, if any), then replace:

pTemplate.Export(l_val);

with:

(pTemplate as IExporter).Export(l_val);
blong
  • 2,145
  • 13
  • 23
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • OK. Thank you very much for your answer and your info about late-bound and early-bound call. I still don't understand it but I will try to find the articles about it. – FZS Oct 13 '16 at 01:58
  • Early-binding is evaluated at compile-time using statically defined member offsets, vtables, etc, just like with normal classes. Late-binding is handled at runtime using `IDispatch.GetIDsOfNames()` and `IDispatch.Invoke()`, so it has more flexibility but at the cost of more overhead. – Remy Lebeau Oct 13 '16 at 02:05
  • So, early-binding is just like normal class, define member at design-time and late-binding defined member at runtime, not in design-time. OK, thanks again, Remy. – FZS Oct 13 '16 at 02:15
  • For the record: I deeply regret that a serious question about Delphi and COM get's downvoted below zero. – Stijn Sanders Oct 13 '16 at 16:32