You might find this handy, I stumbled across it on my harddrive unintentionally. It's a code unit for InnoSetup by Jordan Russel, so credit him if you use it.
Code:
unit SimpleStringList;
interface
uses
Windows, SysUtils;
type
PSimpleStringListArray = ^TSimpleStringListArray;
TSimpleStringListArray = array[0..$1FFFFFFE] of String;
TSimpleStringList = class
private
FList: PSimpleStringListArray;
FCount, FCapacity: Integer;
function Get (Index: Integer): String;
procedure SetCapacity (NewCapacity: Integer);
public
destructor Destroy; override;
procedure Add (const S: String);
procedure AddIfDoesntExist (const S: String);
procedure Clear;
function IndexOf (const S: String): Integer;
property Count: Integer read FCount;
property Items[Index: Integer]: String read Get; default;
end;
implementation
{ TSimpleStringList }
procedure TSimpleStringList.Add (const S: String);
begin
if FCount = FCapacity then
SetCapacity (FCapacity + 8);
FList^[FCount] := S;
Inc (FCount);
end;
procedure TSimpleStringList.AddIfDoesntExist (const S: String);
begin
if IndexOf(S) = -1 then
Add (S);
end;
procedure TSimpleStringList.SetCapacity (NewCapacity: Integer);
begin
ReallocMem (FList, NewCapacity * SizeOf(Pointer));
if NewCapacity > FCapacity then
FillChar (FList^[FCapacity], (NewCapacity - FCapacity) * SizeOf(Pointer), 0);
FCapacity := NewCapacity;
end;
procedure TSimpleStringList.Clear;
begin
if FCount <> 0 then Finalize (FList^[0], FCount);
FCount := 0;
SetCapacity (0);
end;
function TSimpleStringList.Get (Index: Integer): String;
begin
Result := FList^[Index];
end;
function TSimpleStringList.IndexOf (const S: String): Integer;
{ Note: This is case-sensitive, unlike TStringList.IndexOf }
var
I: Integer;
begin
Result := -1;
for I := 0 to FCount-1 do
if FList^[I] = S then begin
Result := I;
Break;
end;
end;
destructor TSimpleStringList.Destroy;
begin
Clear;
inherited Destroy;
end;
end.
Bookmarks