Question

Suppose:

1) HelpfulUserAtSO answers my SO question with a snippet copied from his production code:

type
  IReqBase = Interface(IInterface)
  ['{B71BD1C3-CE4C-438A-8090-DA6AACF0B3C4}']
    procedure FillWithTemplateData;
  end;

2) I think Great answer! and blindly copy this into my production code.

3a) We both distribute our apps and user X wants to install both executables on his computer.
What are the consequences?

3b) I buy up HelpfulUserAtSO's company and want to integrate his code (containing the interface definition) into mine (containing the copy. Assume no scoping conflicts).
What are the consequences?

After all a GUID should be 'globally unique'...

Was it helpful?

Solution

If the same GUID are used not within the same process, this is safe to have the same GUID defined. But if, e.g. you access them via COM, it will definitively be confusing.

If you use diverse interfaces with the same GUID in the same process, e.g. by sharing Delphi code units, you may definitively have issues. By convention, an unique GUID should define an unique signature (i.e. set of methods), so the code may think that a given class instance implements all methods of the interface, and it won't be the case. As a result, the internal execution lookup tables (IMT) won't match. You will get a lot of A/V when calling methods.

IMT interface table

Take a look at this very complete article for details about how interfaces work, and what is this internal IMT lookup table. The same GUID would mean the same IMT table, which won't be the case for you, so it will just break at runtime.

OTHER TIPS

Just experienced an error due to using duplicated GUID for a new interface that's copied from another.

The consequence was that, since I use Supports, although I was intended to call InterfaceB.Method, but InterfaceA.Method1 got called wrongly even it has a different method signature...I found that with the IDE debugger.

The compiler really should report duplicated interface GUIDs as an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top