unit UTGUIDList;
interface
type
TGUIDList =
class
private
FGUIDList:
Array of TGUID;
FCount: Integer;
function GetItem(
Index: Integer): TGUID;
procedure SetItem(
Index: Integer;
const Value: TGUID);
function GetItemString(
Index: Integer):
string;
procedure SetItemString(
Index: Integer;
const Value:
string);
public
constructor Create;
virtual;
destructor Destroy;
override;
property Item[
Index: Integer]: TGUID
read GetItem
write SetItem;
default;
property ItemString[
Index: Integer]:
string read GetItemString
write SetItemString;
procedure Clear;
function Add(aGUID: TGUID): Integer;
function AddFromString(aGUIDString:
string): Integer;
procedure Delete(
Index: Integer);
overload;
function Delete(aGUID: TGUID): boolean;
overload;
function IndexOf(aGUID: TGUID): Integer;
overload;
function IndexOf(aGUIDString:
string): Integer;
overload;
function IsInList(aGUID: TGUID): boolean;
overload;
function IsInList(aGUIDString:
string): boolean;
overload;
property Count: Integer
read FCount;
end;
implementation
uses
SysUtils;
{ TGUIDList }
function TGUIDList.Add(aGUID: TGUID): Integer;
begin
inc(FCount);
setlength(FGUIDList, FCount);
FGUIDList[FCount-1] := aGUID;
result := FCount-1;
end;
function TGUIDList.AddFromString(aGUIDString:
string): Integer;
begin
result := Add(StringToGUID(aGUIDString));
end;
procedure TGUIDList.Clear;
begin
FCount := 0;
setlength(FGUIDList, FCount);
end;
constructor TGUIDList.Create;
begin
inherited;
Clear;
end;
procedure TGUIDList.Delete(
Index: Integer);
var
i: Integer;
begin
for i :=
Index to FCount-2
do begin
FGUIDList[i] := FGUIDList[i+1];
end;
dec(FCount);
setlength(FGUIDList, FCount);
end;
function TGUIDList.Delete(aGUID: TGUID): boolean;
//true if aGUID was found and deleted
var
i: Integer;
begin
result := false;
i := IndexOf(aGUID);
if i<0
then exit;
Delete(i);
result := true;
end;
destructor TGUIDList.Destroy;
begin
Clear;
inherited;
end;
function TGUIDList.GetItem(
Index: Integer): TGUID;
begin
result := FGUIDList[
Index];
end;
function TGUIDList.GetItemString(
Index: Integer):
string;
begin
result := GUIDToString(FGuidList[
Index]);
end;
function TGUIDList.IndexOf(aGUID: TGUID): Integer;
//result := -1 if aGUID was not found
var
i: integer;
begin
result := -1;
for i := 0
to FCount-1
do begin
if IsEqualGUID(aGUID, FGUIDList[i])
then begin
result := i;
break;
end;
end;
end;
function TGUIDList.IndexOf(aGUIDString:
string): Integer;
//result := -1 if aGUIDString was not found
begin
result := IndexOf(StringToGUID(aGUIDString));
end;
function TGUIDList.IsInList(aGUID: TGUID): boolean;
begin
result := IndexOf(aGUID) >= 0;
end;
function TGUIDList.IsInList(aGUIDString:
string): boolean;
begin
result := IsInList(StringToGUID(aGUIDString));
end;
procedure TGUIDList.SetItem(
Index: Integer;
const Value: TGUID);
begin
FGUIDList[
Index] := Value;
end;
procedure TGUIDList.SetItemString(
Index: Integer;
const Value:
string);
begin
FGUIDList[
Index] := StringToGUID(Value);
end;
end.