Recent

Author Topic: [solved] access ADO field value thru ComObj, Variants  (Read 498 times)

CapelliC

  • Jr. Member
  • **
  • Posts: 58
[solved] access ADO field value thru ComObj, Variants
« on: June 25, 2020, 05:04:38 pm »
So far, the COM interface provided by CreateOLEObject('ADODB.Connection') is working for my purpose. It also serve collection items easily.

But when I try to get the Field.Value I have this error 'EVariantInvalidOpError' with message Invalid variant operation. Any hint to bypass this problem ? Have tried some silly workaround, like using VarCopyNoInd (just to find it's not implemented actually...)

Another quirk... while Field properties like Name are available, the Type cannot be obtained. The compiler complains about

    writeln(field_a.type); // ko
my_test.pas(79,21) Fatal: Syntax error, "identifier" expected but "TYPE" found

I think the two problems are related, since seems the compiler does know about IDispatch. Of course, a mere supposition...

TIA for any help
« Last Edit: July 21, 2020, 03:58:06 pm by CapelliC »

korba812

  • Full Member
  • ***
  • Posts: 142
Re: access ADO field value thru ComObj, Variants
« Reply #1 on: June 25, 2020, 05:17:50 pm »
To use identifiers with restricted names (like pascal keywords) you must precede the identifier name with '&':
Code: Pascal  [Select][+][-]
  1. writeln(field_a.&type);

CapelliC

  • Jr. Member
  • **
  • Posts: 58
Re: access ADO field value thru ComObj, Variants
« Reply #2 on: June 25, 2020, 05:34:58 pm »
Thanks, that's useful. Free Pascal is a rather large topic and I have a lot to learn...

CapelliC

  • Jr. Member
  • **
  • Posts: 58
Re: access ADO field value thru ComObj, Variants
« Reply #3 on: July 21, 2020, 03:57:46 pm »
Seems I was calling the wrong COM initialization function.
Instead of CoInitialize, now I call CoInitializeEx(nil,0) and the problem seems to be solved.

 

TinyPortal © 2005-2018