Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6137381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:43:09+00:00 2026-05-23T17:43:09+00:00

I wrote this code in Delphi XE which assign the GUID of the interface

  • 0

I wrote this code in Delphi XE which assign the GUID of the interface from GUID const. the code compile ok, but I want to know if this a valid declaration?

const
  IID_IFoo: TGUID = '{00000000-6666-6666-6666-666666666666}';
type
  IFoo = interface(IDispatch)
    [IID_IFoo]
    //properties
    //methods
  end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:43:10+00:00Added an answer on May 23, 2026 at 5:43 pm

    You can do this, but the question is why would you want to ?

    If you wish to refer to the GUID of an interface rather than the name of the interface, then as long as that interface has an associated IID (GUID) then you can use the interface name where a TGUID is expected:

    type
      IFoo = interface(IDispatch)
        ['{00000000-6666-6666-6666-666666666666}']
        //properties
        //methods
      end;
    
    // meanwhile, elsewhere in the project...
    
      sFooIID := GUIDToString(IFoo);
    

    This is a less “noisy” declaration of the interface and avoids the possibility that you might declare/reference an IID constant which isn’t actually associated with the interface you think it is (or which hasn’t been associated with that IID at all).

    const
      IID_Foo = '{00000000-6666-6666-6666-666666666666}';
      IID_Bar = '{00000000-6666-6666-6666-777777777777}';
    
    type
      IFoo = interface(IDispatch)
        [IID_Bar]    // WHOOPS!
        :
      end;
    
      IBar = interface(IDispatch)
        // WHOOPS again!!
        :
      end;
    
    
    // Meanwhile, elsewhere in the project
    
    sBarID := GUIDToString(IID_Bar);   // Works, but is the IID of IFoo, not IBar
    sFooID := GUIDToString(IID_Foo);   // Works, but is an IID not associated with any interface
    

    Using the interface itself as both interface and IID, rather than having a separate const declaration, removes the potential for these mistakes.

    When using separate constant declarations for IID’s – if you absolutely have to – you can protected against one of these problems by never-the-less using interfaces where IID’s are expected. But this arguably makes things worse in the case where the wrong IID has been used for a particular interface:

    // Cannot make the mistake of using an interface as a GUID if it has no IID at all
    
    sBarID := GUIDToString(IBar);   // Does not compile - IBar has no IID
    
    
    // But if it's the wrong IID then you get results that are "correct" but not expected:
    
    a := GUIDToString(IFoo);
    b := GUIDToString(IID_Foo);
    
      a <> b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert function object to function. I wrote this code, but it
I wrote this code. The constructor works normally, but in the destructor I get
If I wrote this code: typeof(myType).TypeHandle Would it use reflection? How much different from:
I wrote this snippet of code and I assume len is tail-recursive, but a
I want to write some code (in Delphi) to get this XML scheme, I
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this code in C# to encrypt a string with a key: private
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I was trying to understand something with pointers, so I wrote this code: #include
I wrote this tiny code: #include <stdio.h> int main() { size_t temp; temp =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.