Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert from string to GUID?

251 views
Skip to first unread message

Robert Oschler

unread,
Jul 25, 2002, 1:24:59 PM7/25/02
to
I want to use a GUID as an identifier for a file format that my program
creates. So I created a 'const' item like so:

const
CUSTOM_FILE_FORMAT_ID = ['{D60560E0-9FF2-11D6-BD59-00104B3458C5}'];

type
TCustomFileFormatHeader = packed record
ID: TGUID;
end;

What I don't know how to do is convert the editor generated GUID to the
16-byte binary value that TCustomFileFormatHeader.ID requires so I can
initialize the field. How do I do this? Also what _is_ the data format of
the editor generated GUID (Ctrl-Shift-G)? The format used in GUID's is
unfamilar to me: hex-numbers, separated by dashes, enclosed by curly braces,
then single quotes, then square brackets. What format does that represent,
set of bytes, etc?

thx

Robert Oschler

unread,
Jul 25, 2002, 1:40:13 PM7/25/02
to

"Robert Oschler" <Osc...@earthlink.net> wrote in message
news:3d403543_2@dnews...

> I want to use a GUID as an identifier for a file format that my program
> creates. So I created a 'const' item like so:
>
<snip>

Ok nevermind. The answer was simple. Store only the string part of the
GUID in the 'const' item CUSTOM_FILE_FORMAT_ID and use
StringToGUID(CUSTOM_FILE_FORMAT_ID ) to prep the GUID field.


Guido Gybels

unread,
Jul 25, 2002, 1:46:06 PM7/25/02
to
"Robert Oschler" <Osc...@earthlink.net> wrote in message
news:3d403543_2@dnews...
> What I don't know how to do is convert the editor generated GUID to the
> 16-byte binary value that TCustomFileFormatHeader.ID requires

TGUID is a packed record, declared as follows:

TGUID = packed record
D1: Longword;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;

As you can see, the separators in the string representation of the GUID,
represent the separation between the D1-D4 fields of the TGUID. The record
itself is already a binary value. The string REPRESENTS each field of the
record in hexadecimal format.
You don't need to do the calculation yourself though, Delphi allows you to
declare a constant that uses a string literal to specify the GUID value:

const AnyGUID: TGUID = '{12345678-0A0B-0C0D-9000-000000000000}';

You can then use this constant to refer to the binary GUID in your code.

Guido


--
Guido Gybels
www.optimalcode.com/Guido

John Herbster

unread,
Jul 25, 2002, 6:58:40 PM7/25/02
to
> TGUID = packed record
> D1: Longword;
> D2: Word;
> D3: Word;
> D4: array[0..7] of Byte;
> end;

How in the world did this ever come to be?
Why not just use "array[0..15] of byte"?


William Meyer

unread,
Jul 25, 2002, 7:27:44 PM7/25/02
to
John Herbster wrote:

> How in the world did this ever come to be?
> Why not just use "array[0..15] of byte"?

Or array[0..3] of LongWord?

And why does the string presentation not match the binary layout? It looks
like:

TGUID = packed record
D1 : LongWord;
D2 : Word;
D3 : Word;
D4 : Word;
D5 : array[0..5] of Byte;
end;

Or maybe more like D5: TribpleWord; (as if we had one <g>)

Who are those guys. anyway? <g>

--
Bill
Education guarantees neither good sense nor rational thinking.
- Posted with XanaNews -

Robert Oschler

unread,
Jul 25, 2002, 8:01:38 PM7/25/02
to

"William Meyer" <wmhm...@earthlink.net> wrote in message
news:3d408970_2@dnews...

> John Herbster wrote:
>
end;
>
> Or maybe more like D5: TribpleWord; (as if we had one <g>)
>
> Who are those guys. anyway? <g>
>

Or how come you can't compare two GUID variables without the use of a
special function IsEqualGUID?


Rudy Velthuis (TeamB)

unread,
Jul 25, 2002, 8:30:13 PM7/25/02
to
In article <3d409608_2@dnews>, William Meyer says...

> John Herbster wrote:
>
> > It's that old big/little-endian problem. <g> --JohnH
>
> Yeah, well.... but still, why does the string representation have a
> different grouping than the record?

Who knows? Who invented them anyway? <g>
--
Rudy Velthuis (TeamB)

"If we knew what it was we were doing, it would not be called research,
would it?" -- Albert Einstein

William Meyer

unread,
Jul 25, 2002, 8:37:26 PM7/25/02
to
Rudy Velthuis (TeamB) wrote:

> Who knows? Who invented them anyway? <g>

Well, there's plenty of info here:
http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt

And some more here:

http://gsraj.tripod.com/com/basic_com/naming_guid.html

The latter reference makes it look as though the different formatting of
string and record is based on the original format specs. (But it still
seems goofy to me <g>.)

William Meyer

unread,
Jul 25, 2002, 8:21:28 PM7/25/02
to
John Herbster wrote:

> It's that old big/little-endian problem. <g> --JohnH

Yeah, well.... but still, why does the string representation have a
different grouping than the record?

--

John Herbster

unread,
Jul 25, 2002, 8:18:31 PM7/25/02
to
"William Meyer" <wmhm...@earthlink.net> wrote

> Or array[0..3] of LongWord?

It's that old big/little-endian problem. <g> --JohnH


0 new messages