Jump to content
Sign in to follow this  
mderie

About TGUID type...

Recommended Posts

Hi folks,

 

I've discover this a bit by misluck :

 

  function GenerateAppGUID: TGuid;
  const
    guid : TGUID = '{481E85E5-3874-4FCB-BEA1-B65D640AE6D3}';
  begin
    result := guid; // Compile fine !
  end;

 

  function GenerateAppGUID: TGuid;
  begin
     Result := '{481E85E5-3874-4FCB-BEA1-B65D640AE6D3}'; // E2010 Incompatible types: 'TGUID' and 'string'
  end;

 

I find this quite annoying...

 

Regards

Share this post


Link to post
12 minutes ago, mderie said:

I find this quite annoying...

 

Why is it annoying? TGUID is not a string. You can write your function as:

 

function GenerateAppGUID: TGuid;
begin
  Result := StringToGUID('{481E85E5-3874-4FCB-BEA1-B65D640AE6D3}');
end;

 

Share this post


Link to post

Recent Delphi versions also allow this construct:

function GenerateAppGUID: TGuid;
begin
  Result := TGUID.Create('{481E85E5-3874-4FCB-BEA1-B65D640AE6D3}');
end;

 

Share this post


Link to post

It is annoying since the compiler do the type conversion in the declaration and not in the assignement !

Share this post


Link to post

Using a local TGUID constant seems the best solution.

It is clean and fast (no string/hex conversion involved, just copy the TGUID record bytes).

No need to make anything else, or ask for a feature request I guess, because it would be purely cosmetic.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×