Recent

Author Topic: CORBA interface and Variants  (Read 1062 times)

JdeHaan

  • Full Member
  • ***
  • Posts: 132
CORBA interface and Variants
« on: April 16, 2024, 12:51:37 pm »
Hi,

For various reasons I use CORBA interfaces. In my code I also use Variants, to support different types of value in a variable. This may include an interface value.

At some point I need to check if a Variable (of type Variant) is a (CORBA) interface. I use the following code for that:

Code: Pascal  [Select][+][-]
  1. isSymTabEntry := VarSupports(Value, StringToGUID(ISymTabEntry_GUID), SymTabEntry);
  2.  
Here, Value is a variable of type Variant,
ISymTabEntry_GUID, is a string constant, such as:
'{DCD95BA9-90CB-9AA2-0090-DBA0749AF179}'
and SymTabEntry is a CORBA interface ISymTabEntry, defined as :

Code: Pascal  [Select][+][-]
  1.   ISymTabEntry = interface
  2.     [ISymTabEntry_GUID]
  3.     function getName: String;
  4.     //etc…
  5.   end;
  6.  
It doesn’t seem to work. Function getName produces the GUID string constant instead of the name of the SymTabEntry…
Could it be that only COM interfaces can be used with VarSupports?

Is there maybe another way of retrieving an Interface value/variable from a Variant value?

Any suggestion is appreciated.

Regards, J



------------------------------
I use trunk Lazarus and FPC on MacOS Sonoma

cdbc

  • Hero Member
  • *****
  • Posts: 1237
    • http://www.cdbc.dk
Re: CORBA interface and Variants
« Reply #1 on: April 16, 2024, 02:17:18 pm »
Hi
Have you tried:
Code: Pascal  [Select][+][-]
  1. S:= SymTabEntry.GetName(); // NOTE the ()
Funny thing about corba-interfaces: *they typecast to string* i.e.: the string representation of the guid.
So given your method returns a string, if you don't add the parantheses / braces, it doesn't count that as a method-call and returns the string-rep. of the interface... At least that's my experience so far...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11583
  • FPC developer.
Re: CORBA interface and Variants
« Reply #2 on: April 16, 2024, 03:11:07 pm »
Afaik the methods to query nearly everything from an interface are in iunknown (the com base interface).

So yeah, probably that won't work.

JdeHaan

  • Full Member
  • ***
  • Posts: 132
Re: CORBA interface and Variants
« Reply #3 on: April 16, 2024, 04:06:22 pm »
Ok, thanks.

@cdbc, I tried but unfortunately I get the same result...

Edit:
Just found out that the VarSupports never returns TRUE, so this is not working
« Last Edit: April 16, 2024, 04:11:04 pm by JdeHaan »

Thaddy

  • Hero Member
  • *****
  • Posts: 14819
  • Censorship about opinions does not belong here.
Re: CORBA interface and Variants
« Reply #4 on: April 16, 2024, 04:27:00 pm »
For various reasons I use CORBA interfaces.
Bad habit. Give me one various reason. Then I might be able to help.
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

JdeHaan

  • Full Member
  • ***
  • Posts: 132
Re: CORBA interface and Variants
« Reply #5 on: April 16, 2024, 04:56:48 pm »
I know it's not optimal to use Corba interfaces.
But, the problem I was facing was that in order to use a COM interface, my class definition had to inherit from TInterfacedObject, but I also had to inherit from another class. To prevent that I used Corba.
I'm now thinking of creating my own value type, based on a variant record instead of a Variant type. So, basically:

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyRec = record
  3.     case byte of
  4.      0: (IntVal: Integer);
  5.      1: (FloatVal: Real);
  6.      2: (IntfVal: IMyCorbaInterface);
  7.   end;
  8.  
 

PascalDragon

  • Hero Member
  • *****
  • Posts: 5541
  • Compiler Developer
Re: CORBA interface and Variants
« Reply #6 on: April 16, 2024, 08:35:43 pm »
But, the problem I was facing was that in order to use a COM interface, my class definition had to inherit from TInterfacedObject, but I also had to inherit from another class. To prevent that I used Corba.

You don't have to inherit from TInterfacedObject, but what you have to do is to implement the methods of IInterface/IUnknown (which is what TInterfacedObject does).

 

TinyPortal © 2005-2018