* added TryStringToGuid function (former StringToGuid is using this now)

git-svn-id: trunk@13237 -
This commit is contained in:
ivost 2009-06-05 20:35:12 +00:00
parent db429f2d48
commit 91ae3e8788
2 changed files with 15 additions and 7 deletions

View File

@ -33,6 +33,7 @@ function Supports(const AClass: TClass; const IID: TGUID): Boolean; overload;
function Supports(const AClass: TClass; const IID: Shortstring): Boolean; overload;
//function CreateGUID(out Guid: TGUID): HResult;
function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
function StringToGUID(const S: string): TGUID;
function GUIDToString(const GUID: TGUID): string;
function IsEqualGUID(const guid1, guid2: TGUID): Boolean;

View File

@ -64,6 +64,13 @@ end;
function StringToGUID(const S: string): TGUID;
begin
if not TryStringToGUID(S, Result) then
raise EConvertError.CreateFmt(SInvalidGUID, [S]);
end;
function TryStringToGUID(const S: string; out Guid: TGUID): Boolean;
function HexChar(c: Char): Byte;
begin
@ -90,10 +97,9 @@ var
src: PChar;
dest: PByte;
begin
if ((Length(S)<>38) or
(s[1]<>'{')) then
raise EConvertError.CreateFmt(SInvalidGUID, [s]);
dest:=PByte(@Result);
if ((Length(S)<>38) or (s[1]<>'{')) then
Exit(False);
dest:=PByte(@Guid);
src:=PChar(s);
inc(src);
for i:=0 to 3 do
@ -101,7 +107,7 @@ begin
inc(src, 8);
inc(dest, 4);
if src[0]<>'-' then
raise EConvertError.CreateFmt(SInvalidGUID, [s]);
Exit(False);
inc(src);
for i:=0 to 1 do
begin
@ -111,7 +117,7 @@ begin
inc(dest);
inc(src, 4);
if src[0]<>'-' then
raise EConvertError.CreateFmt(SInvalidGUID, [s]);
Exit(False);
inc(src);
end;
dest^:=HexByte(src);
@ -121,7 +127,7 @@ begin
inc(dest);
inc(src, 2);
if src[0]<>'-' then
raise EConvertError.CreateFmt(SInvalidGUID, [s]);
Exit(False);
inc(src);
for i:=0 to 5 do
begin
@ -129,6 +135,7 @@ begin
inc(dest);
inc(src, 2);
end;
Result := True;
end;