Recent

Author Topic: is and as operators with CORBA interfaces.  (Read 9566 times)

soerensen3

  • Full Member
  • ***
  • Posts: 213
is and as operators with CORBA interfaces.
« on: December 27, 2017, 03:18:10 am »
If I use "is" and "as" operators with CORBA interfaces I get:
Code: Pascal  [Select][+][-]
  1. Error: Class or COM interface type expected, but got "IP3DStreamableContainer"
  2. Explanation: Some operators, such as the AS operator, are only applicable to classes or COM interfaces.
Does it mean it does not work with corba? I'm asking because here it is stated differently:
Quote
The as and is operators also work on interfaces (both COM and CORBA). They can be used to check whether an interface also implements another interface as in the following example... https://www.freepascal.org/docs-html/ref/refsu51.html#x154-17600012.8.7

I'm wondering if the error is somewhere else (maybe because of an implicit IUnknown descendance) so it would be good to know if the message or the documentation is at fault.
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: is and as operators with CORBA interfaces.
« Reply #1 on: December 27, 2017, 07:30:38 am »
Is and As operators require that the interface has a GUID defined. In case of com this is the known GUID in case of CORBA this is a unique string (I think). With out them there is no way for the compiler to know.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #2 on: December 27, 2017, 08:50:48 am »
If you want to use CORBA with is and as you need an IDL typelibrary even when used locally. CORBA is usually a technically bad choice for local interfaces. Can you explain why you want to use CORBA? Or did you read the only shitty opinionated and ill-informed chapter in "Modern ObjectPascal" by M.Kamburelis? (Very good! except he does not understand interfaces and is stubborn about it, so skip that chapter (9)).

So: plz explain?

Note the manual does not include that and so is partially incorrect (CORBA needs IDL locally). Later on the manual even contradicts itself and explains it NEEDS to be COM, as the compiler says.
See last line of https://www.freepascal.org/docs-html/ref/refsu51.html#x154-17600012.8.7 which says:
"Although the interfaces must be COM interfaces, "

I'll see what I can do. There is a small example on how to use CORBA correctly on the wiki http://wiki.freepascal.org/Interfaces
That shows it is more cumbersome to use than COM.
« Last Edit: December 27, 2017, 11:19:13 am by Thaddy »
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #3 on: December 27, 2017, 11:32:16 am »
CORBA is usually a technically bad choice for local interfaces.
@soerensen3, please don't believe this statement, Thaddy is not right.
There also is no need for a "IDL-typelibrary', simply add a UID-string to the interface definition as taazz writes. MSEide has LeftClick-'Insert UID' in source editor in order to generate a UID-string based on a interface number. "is" and "as" can then be used with objectinstance and CORBA interface.
Code: Pascal  [Select][+][-]
  1. {$interfaces corba}
  2.  itest = interface         ['AA']{0}
  3.  end;
  4.  itest1 = interface(itest) ['gA']{1}
  5.   procedure test();
  6.  end;
  7. [...]
  8.  if theobjectinstance is itest1 then begin
  9.  end;
  10.  
MSEgui also has "getcorbainterface()" in order to fetch a CORBA interface pointer from an objectinstance. Maybe there is a FPC-internal function now which can do the same, I don't remember.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #4 on: December 27, 2017, 11:40:51 am »
CORBA is usually a technically bad choice for local interfaces.
@soerensen3, please don't believe this statement, Thaddy is not right.
Well, then: give some compilable code. I am the first to admit it if I am wrong, and it still would be only partially:how do you explain the documentation? At best it is by accident. (And I still think local CORBA is unusable compared to COM interfaces when used locally, unless you are from outer space.) Point is: it does not matter if it works, but how it works and why it works. Noon use CORBA on a single machine: makes no sense. You do not have to use an (CORBA) interface if it is localanyway. Then you do not understand the concepts of CORBA and COM. COM has local merit because of memory management. CORBA hasn't....
« Last Edit: December 27, 2017, 11:49:00 am by Thaddy »
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #5 on: December 27, 2017, 11:48:55 am »
Well, then: give some compilable code.
See MSEide+MSEgui:
https://gitlab.com/mseide-msegui/mseide-msegui
MSEide+MSEgui is full of "useful" code with CORBA-interfaces. ;-)
The only thing what is wrong with CORBA-interfaces is the name which is inappropriate IMHO.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #6 on: December 27, 2017, 11:50:44 am »
I know your code, I don't use it (anymore). I sometimes recommend it though. I simply ask for a SIMPLE example why you should use CORBA over COM locally....so I can prove it is not a right solution.
There's a good reason that CORBA is not mainstream for local.
« Last Edit: December 27, 2017, 11:56:06 am by Thaddy »
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #7 on: December 27, 2017, 12:12:45 pm »
One uses CORBA- (or base- or raw-) interfaces when one don't want to involve memory management and reference counting but to provide a method interface to an arbitrary class. See for example the "ifi" interface family of MSEgui
Code: Pascal  [Select][+][-]
  1. {$ifdef FPC}{$mode objfpc}{$h+}{$interfaces corba}{$endif}
  2. [...]
  3.  inullinterface = interface
  4.   //no referencecount, only for fpc, not available in delphi
  5.  end;
  6. [...]
  7.  iobjectlink = interface(inullinterface)
  8.   procedure link(const source,dest: iobjectlink; valuepo: pointer = nil;
  9.                         ainterfacetype: pointer = nil; once: boolean = false);
  10.   procedure unlink(const source,dest: iobjectlink; valuepo: pointer = nil);
  11.                //source = 1 -> dest destroyed
  12.   procedure objevent(const sender: iobjectlink; const event: objecteventty);
  13.   function getinstance: tobject;
  14.  end;
  15. [...]
  16.  iificlient = interface(iobjectlink)[miid_iificlient]
  17.   procedure setifiserverintf(const aintf: iifiserver);
  18.   function getdefaultifilink: iificlient;
  19.  end;
  20. [...]
  21.  iifilink = interface(iificlient)[miid_iifilink]
  22.   function getifilinkkind: ptypeinfo;
  23.   function getobjectlinker: tobjectlinker;
  24.  end;
  25.  
  26.  iifiexeclink = interface(iifilink)[miid_iifiexeclink]
  27.   procedure execute(const force: boolean = false);
  28.  end;
  29.  
  30.  iififormlink = interface(iifilink)[miid_iififormlink]
  31.  end;
  32.  
  33.  iifidialoglink = interface(iifilink)[miid_iifidialoglink]
  34.   function showdialog(out adialog: tactcomponent): modalresultty;
  35.  end;
  36.    
  37.  iifidatalink = interface(iifilink)[miid_iifidatalink]
  38.   procedure updateifigriddata(const sender: tobject; const alist: tdatalist);
  39.   function getgriddata: tdatalist;
  40.   function getvalueprop: ppropinfo;
  41.   procedure updatereadonlystate;
  42.  end;
  43.  
  44.  iifigridlink = interface(iifilink)[miid_iifigridlink]
  45.   function appendrow(const checkautoappend: boolean = false): integer;
  46.   function getrowstate: tcustomrowstatelist;
  47.   procedure rowchanged(const arow: integer);
  48.   procedure rowstatechanged(const arow: integer);
  49.   procedure layoutchanged;
  50.   function canclose1: boolean;
  51.  end;
  52.  
Every class which implements "iifidatalink" can be automatically bound to an ifi-data-endpoint component. Automatically unlinking when one of the connected instances has been destroyed is handled by "iobjectlink" and its implementor "tobjectlinker".
« Last Edit: December 27, 2017, 12:17:49 pm by mse »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #8 on: December 27, 2017, 12:18:44 pm »
A simple compilable example... This is not good enough. This is science by verification (old school). I only do science by falsification (proper school).
My signature also holds for computer science.
« Last Edit: December 27, 2017, 12:20:29 pm by Thaddy »
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #9 on: December 27, 2017, 12:24:17 pm »
So you state that one should use COM interfaces if one has to solve a task like the MSEgui ifi-system.
Please explain why, I don't get it why reference counting is necessary.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #10 on: December 27, 2017, 03:03:44 pm »
A simple compilable example... This is not good enough. This is science by verification (old school). I only do science by falsification (proper school).
My signature also holds for computer science.
No I am asking for simple example code. MSExxx is way to complicate to analyze for a forum question.
I bet you can not make a simple example that actually compiles and is useful and superior to COM. Otherwise you would have done so by now.
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #11 on: December 27, 2017, 03:46:32 pm »
No I am asking for simple example code.
As ordered:
Code: Pascal  [Select][+][-]
  1. program test2;
  2. {$ifdef FPC}{$mode objfpc}{$h+}{$endif}
  3. {$ifdef mswindows}{$apptype console}{$endif}
  4. uses
  5.  {$ifdef FPC}{$ifdef unix}cthreads,cwstring,{$endif}{$endif}
  6.  sysutils;
  7.  
  8. type
  9.  {$interfaces corba}
  10.  
  11.  ivisibility = interface
  12.   procedure show();
  13.   procedure hide();
  14.  end;
  15.  
  16.  ttest = class(tobject,ivisibility)
  17.   protected
  18.    procedure show();
  19.    procedure hide();
  20.  end;
  21.  
  22.  
  23. { ttest }
  24.  
  25. procedure ttest.show();
  26. begin
  27.  //enter code to show the object here
  28. end;
  29.  
  30. procedure ttest.hide();
  31. begin
  32.  //enter code to hide the object here
  33. end;
  34.  
  35. procedure hideobject(const aintf: ivisibility);
  36. begin
  37.  aintf.hide();
  38. end;
  39.  
  40. var
  41.  test1: ttest;  
  42. begin
  43.  test1:= ttest.create();
  44.  hideobject(ivisibility(test1));
  45.  test1.destroy();
  46. end.
  47.  
Please explain why "ivisibility" needs reference counting.
« Last Edit: December 27, 2017, 04:31:38 pm by mse »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #12 on: December 27, 2017, 03:50:38 pm »
Where's the is and as test?
Sent back... O:-) 8-) Stay on topic. That's the whole point. (yes your code compiles, but I gave a link that also cmpiles)
Show is and as with CORBA....
Now... who is right?
« Last Edit: December 27, 2017, 03:53:50 pm by Thaddy »
Specialize a type, not a var.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: is and as operators with CORBA interfaces.
« Reply #13 on: December 27, 2017, 03:59:14 pm »
Please answer my question.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: is and as operators with CORBA interfaces.
« Reply #14 on: December 27, 2017, 04:03:38 pm »
Please answer my question.
I did.
I am answering OP's question, not yours, did you miss something? Your example does not contain is nor as. Your code compiles and works, but that is not the issue....
The issue is that CORBA has no is or as locally.
Specialize a type, not a var.

 

TinyPortal © 2005-2018