Recent

Author Topic: Problem with class implementing multiple interfaces  (Read 1704 times)

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Problem with class implementing multiple interfaces
« on: November 13, 2023, 05:06:40 pm »
Sorry guys but today interfaces have decided to get me wrong badly.

See the following code, and please let me know what I am doing wrong. The output of the execution here is below.

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$INTERFACES CORBA}
  4.  
  5. type
  6.  
  7.   IExample1 = interface
  8.     procedure SomeMethod1();
  9.   end;
  10.   IExample2 = interface
  11.     procedure SomeMethod21();
  12.     procedure SomeMethod22();
  13.   end;
  14.   IExample3 = interface
  15.     procedure SomeMethod3();
  16.   end;
  17.  
  18.   TExampleImplementation = class(TObject, IExample1, IExample2, IExample3)
  19.     public
  20.       procedure SomeMethod1();
  21.      
  22.       procedure SomeMethod21();
  23.       procedure SomeMethod22();
  24.      
  25.       procedure SomeMethod3();
  26.   end;
  27.  
  28. procedure TExampleImplementation.SomeMethod1();
  29. begin
  30.   Writeln('In SomeMethod1();');
  31. end;
  32. procedure TExampleImplementation.SomeMethod21();
  33. begin
  34.   Writeln('In SomeMethod21();');
  35. end;
  36. procedure TExampleImplementation.SomeMethod22();
  37. begin
  38.   Writeln('In SomeMethod22();');
  39. end;
  40. procedure TExampleImplementation.SomeMethod3();
  41. begin
  42.   Writeln('In SomeMethod3();');
  43. end;
  44.  
  45. var
  46.   o: TObject;
  47. begin
  48.   o := TExampleImplementation.Create();
  49.  
  50.   (o as IExample1).SomeMethod1();
  51.   (o as IExample2).SomeMethod21();
  52.   (o as IExample2).SomeMethod22();
  53.   (o as IExample3).SomeMethod3();
  54.  
  55.   o.Destroy();
  56. end.
  57.  

Code: Bash  [Select][+][-]
  1. In SomeMethod1();
  2. In SomeMethod1();
  3. In SomeMethod21();
  4. In SomeMethod1();
  5.  
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Problem with class implementing multiple interfaces
« Reply #1 on: November 13, 2023, 05:14:10 pm »
This instead works well.

So what am I doing wrong with CORBA interfaces?
Please help!

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. type
  4.  
  5.   IExample1 = interface
  6.     ['{B128FB28-712B-4A0A-9475-A1226BB8729A}']
  7.     procedure SomeMethod1();
  8.         end;
  9.   IExample2 = interface
  10.     ['{166A9ABC-CD84-4A12-8724-9F33B3226712}']
  11.     procedure SomeMethod21();
  12.     procedure SomeMethod22();
  13.         end;
  14.   IExample3 = interface
  15.     ['{BA157E30-4D3A-442B-ADC6-F2C7770E5C7E}']
  16.     procedure SomeMethod3();
  17.         end;
  18.  
  19.   TExampleImplementation = class(TInterfacedObject, IExample1, IExample2, IExample3)
  20.     public
  21.       procedure SomeMethod1();
  22.      
  23.       procedure SomeMethod21();
  24.       procedure SomeMethod22();
  25.      
  26.       procedure SomeMethod3();
  27.         end;
  28.  
  29. procedure TExampleImplementation.SomeMethod1();
  30. begin
  31.   Writeln('In SomeMethod1();');
  32. end;
  33. procedure TExampleImplementation.SomeMethod21();
  34. begin
  35.   Writeln('In SomeMethod21();');
  36. end;
  37. procedure TExampleImplementation.SomeMethod22();
  38. begin
  39.   Writeln('In SomeMethod22();');
  40. end;
  41. procedure TExampleImplementation.SomeMethod3();
  42. begin
  43.   Writeln('In SomeMethod3();');
  44. end;
  45.  
  46. var
  47.   o: TObject;
  48. begin
  49.   o := TExampleImplementation.Create();
  50.  
  51.   (o as IExample1).SomeMethod1();
  52.   (o as IExample2).SomeMethod21();
  53.   (o as IExample2).SomeMethod22();
  54.   (o as IExample3).SomeMethod3();
  55.  
  56. end.
  57.  
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

cdbc

  • Hero Member
  • *****
  • Posts: 2772
    • http://www.cdbc.dk
Re: Problem with class implementing multiple interfaces
« Reply #2 on: November 13, 2023, 05:32:40 pm »
Hi
Guid
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Problem with class implementing multiple interfaces
« Reply #3 on: November 13, 2023, 07:19:52 pm »
Hi
Guid
Regards Benny

Thank you, now I understand. Sorry but from documentation I did not get that I need the guid in Corba/Linux.

Ps: just one observation, in com mode compiler requires the guids, in Corba mode not, is there a reason?

Thank you
« Last Edit: November 13, 2023, 07:39:46 pm by Чебурашка »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Stefan Glienke

  • New Member
  • *
  • Posts: 24
Re: Problem with class implementing multiple interfaces
« Reply #4 on: November 14, 2023, 03:48:22 am »
You still need to give them a unique identifier in order for the as-cast to work - opposed to COM where it has to be a guid though it can be a simple string.

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Problem with class implementing multiple interfaces
« Reply #5 on: November 14, 2023, 08:33:50 am »
You still need to give them a unique identifier in order for the as-cast to work - opposed to COM where it has to be a guid though it can be a simple string.

Thanks now is clear.

IMO there should be some extra messages from the compiler when CORBA mode. I posted a feature req.

https://gitlab.com/freepascal.org/fpc/source/-/issues/40521
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

cdbc

  • Hero Member
  • *****
  • Posts: 2772
    • http://www.cdbc.dk
Re: Problem with class implementing multiple interfaces
« Reply #6 on: November 14, 2023, 11:39:16 am »
Hi
I just use the trick with const SGUIDIExample = 'xxx-x--xx-x-xx';
It's so damn convenient with ctrl+shift+g, that I happily type the 1 extra line  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Чебурашка

  • Hero Member
  • *****
  • Posts: 593
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: Problem with class implementing multiple interfaces
« Reply #7 on: November 14, 2023, 11:50:20 am »
Hi
I just use the trick with const SGUIDIExample = 'xxx-x--xx-x-xx';
It's so damn convenient with ctrl+shift+g, that I happily type the 1 extra line  :D
Regards Benny

Of course it is handy, but if one does not know, compiler does not tell a thing and you (me) spend a day seeing weird errors like I did.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

cdbc

  • Hero Member
  • *****
  • Posts: 2772
    • http://www.cdbc.dk
Re: Problem with class implementing multiple interfaces
« Reply #8 on: November 14, 2023, 01:39:12 pm »
Hi
Quote
Of course it is handy, but if one does not know, compiler does not tell a thing and you (me) spend a day seeing weird errors like I did.
True that!
I've seen your ticket, good on you, mate  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018