1
votes

I have a legacy Delphi 2 application that I need to convert from communicating with Notes via OLE Automation to communicating via COM early binding. I am using Delphi 7 since the code base is large and I want to avoid the work of dealing with the Unicode support in the more current versions of Delphi.

The basics are working: the program opens the database then the view and searches for a particular document using the NotesView.GetDocumentByKey method. The GetDocumentByKey call works when the first parameter is a single string cast to an OleVariant as shown below (opening of DB and view not shown).

var
  Key: OleVariant;
const ExactMatch: WordBool = True;
begin
  Key := 'AKeyValue';
  Doc := View.GetDocumentByKey(Key, ExactMatch);

The bad variable type error occurs when the first parameter is a variant array as required when it is desired to search the view based on multiple columns as shown below.

var
  TwoKeysV: OleVariant;
const ExactMatch: WordBool = True;
begin
  TwoKeysV := VarArrayCreate([0, 1], varOleStr);
  TwoKeysV[0]:= WideString('Key1');
  TwoKeysV[1]:= WideString('Key2');
  Doc := View.GetDocumentByKey(TwoKeysV, ExactMatch);

I have tried several variations on the two key assignment statements with no success. For example, just assigning the key string without a cast still produces the bad variable type, and using the StringToOleString function is rejected by the compiler as an invalid assignment (PWideChar to Variant).

1
In the help array of string is what you need to send, did you try to create a real array of string in Delphi and casting it to OleVariant ? (www-01.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/…) NB this is not what the Help indicates: If this method is used under COM, with a keyArray parameter of an array, it must be defined as an array of type Variant. - Emmanuel Gleizer
Tried the idea of creating the key array is a normal Variant and then casting to OleVariant but it produces the same bad variable type error - Keeloid

1 Answers

1
votes

I can't test this, so I'm not sure this works.

HELP: If this method is used under COM, with a keyArray parameter of an array, it must be defined as an array of type Variant

So you need to pass: an array of type Variant

Based on How to use variant arrays in Delphi.

Note: Code edited by Keeloid to match code that worked by casting key string to WideString.

var
  TwoKeysV: OleVariant;
const ExactMatch: WordBool = True;
begin
  TwoKeysV := VarArrayCreate([0, 1], varVariant);
  TwoKeysV[0]:= WideString('Key1');  {WideString = varOleStr}
  TwoKeysV[1]:= WideString('Key2');
  Doc := View.GetDocumentByKey(TwoKeysV, ExactMatch);