1

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).

Keeloid
  • 27
  • 1
  • 5
  • 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 ? (https://www-01.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/com.ibm.designer.domino.main.doc/H_GETDOCUMENTBYKEY_METHOD.html) 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 Nov 24 '15 at 08:10
  • look at http://stackoverflow.com/questions/3619753/how-to-use-variant-arrays-in-delphi – Emmanuel Gleizer Nov 24 '15 at 08:16
  • 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 Nov 24 '15 at 21:34

1 Answers1

1

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);
Community
  • 1
  • 1
Emmanuel Gleizer
  • 1,990
  • 16
  • 26
  • Thanks. That worked. Strangely, the legacy code, which used Delphi 2 OleAuto (late binding) required that the array be of varOleStr. Obviously something about COM/OLE support changed. – Keeloid Nov 25 '15 at 16:44
  • The above code has also proven to work in Delphi 10 Seattle. – Keeloid Nov 30 '15 at 23:26