//Advanced Delphi Systems Code: ads_GUID
unit ads_GUID;
{Copyright(c)2016 Advanced Delphi Systems

 Richard Maley
 Advanced Delphi Systems
 12613 Maidens Bower Drive
 Potomac, MD 20854 USA
 phone 301-840-1554
 dickmaley@advdelphisys.com

 The code herein can be used or modified by anyone.  Please retain references
 to Richard Maley at Advanced Delphi Systems.  If you make improvements to the
 code please send your improvements to dickmaley@advdelphisys.com so that the
 entire Delphi community can benefit.  All comments are welcome.
}
(*
UnitIndex Master Index Implementation Section Download Units
Description: ads_GUID.pas
This unit contains the following routines.

DressStringGUID   GetGUIDFromString   GetNewGUID   GetNewGUIDAsString   GetNewGUIDAsStringUndressed  GetStringFromGUID   UndressStringGUID  

*)
interface
Uses SysUtils;

Function GetGUIDFromString(SGUID: String): TGUID;
Function GetNewGUID: TGuid;
Function GetNewGUIDAsString: String;
Function GetNewGUIDAsStringUndressed: String;
Function UndressStringGUID(SGUID:String): String;
Function DressStringGUID(SGUID:String): String;
Function GetStringFromGUID(GUID: TGUID): String;

implementation


//
Unit Description UnitIndex Master Index
Function GetNewGUIDAsString: String;
Begin
  Result := GetStringFromGUID(GetNewGUID);
End;

//
Unit Description UnitIndex Master Index
Function GetNewGUID: TGUID;
Var
  GUID : TGUID;
Begin
  CreateGUID(GUID);
  Result := GUID;
End;

//
Unit Description UnitIndex Master Index
Function GetGUIDFromString(SGUID: String): TGUID;
Begin
  Result := StringToGUID(SGUID);
End;

//
Unit Description UnitIndex Master Index
Function GetStringFromGUID(GUID: TGUID): String;
Begin
  Result := GUIDToString(GUID);
End;

//
Unit Description UnitIndex Master Index
Function GetNewGUIDAsStringUndressed: String;
Begin
  Result := UndressStringGUID(GetNewGUIDAsString);
End;

//
Unit Description UnitIndex Master Index
Function UndressStringGUID(SGUID:String): String;
Begin
  Result := StringReplace(SGUID,'-','',[rfReplaceAll]);
  Result := StringReplace(Result,'{','',[]);
  Result := StringReplace(Result,'}','',[]);
End;

//
Unit Description UnitIndex Master Index
Function DressStringGUID(SGUID:String): String;
Begin
  Result := Trim(SGUID);
  If Copy(Result,1,1) <> '{' Then Result := '{'+Result;
  If Copy(Result,Length(Result),1) <> '}' Then Result := Result+'}';
  If Length(Result) <> 34 Then Exit;
  Result := Copy(Result,1,9)+'-'+Copy(Result,10,25);
  Result := Copy(Result,1,14)+'-'+Copy(Result,15,21);
  Result := Copy(Result,1,19)+'-'+Copy(Result,20,17);
  Result := Copy(Result,1,24)+'-'+Copy(Result,25,13);
End;

end.
//