[fpc-pascal] corba interfaces - is/as not working properly

Michalis Kamburelis michalis.kambi at gmail.com
Fri Sep 30 16:24:58 CEST 2016


This thread, and my own tests, showed that you need to assign GUIDs to
interfaces to have reliable "is", even for CORBA interfaces.

I'm wondering, would it be possible to improve here things on the
compiler side (at least only in FPC-specific modes or under some
modeswitch), to make things safer?

Propositions:

1. The question "X is IMyInterface", when "IMyInterface" does not have
a GUID, could fail to compile.

  Just like right now "Supports(X, IMyInterface)" does not compile
when "IMyInterface" does not have a GUID. This is better -- the
presence of GUID is checked at compile-time.

  Right now, the "X is IMyInterface" seems like a trap, when the
interfaces can have no GUIDs. Two interfaces without GUIDs are treated
as equal, by the "is" operator. The example code that started this
thread shows how bad are the consequences. I made my own little
example, attaching.

2. I assume "as" operator has the same problem? So "X as IMyInterface"
would benefit from the same safeguard.

3. How about going further, and just making the GUID required at every
interface declaration? Since it's necessary to have reliable "is",
"as", "Supports"...

4. And how about going even more further, and just generate an
internal GUIDs (random, or based on a memory address) when no GUID is
explicitly specified? This way "is", "as", "Supports" always just
work. And it removes the need to do 1., 2., 3. above, of course.

  Is there a drawback to doing this, that I don't see?

Regards,
Michalis

P.S. I have added to
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html
a section documenting it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: guids_are_needed.lpr
Type: text/pascal
Size: 1648 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160930/fc0b88aa/attachment.bin>


More information about the fpc-pascal mailing list