interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TIntArray = array[0..0] of Integer;
TIntList = class(TObject)
private
FCount: LongInt;
FInteger: ^TIntArray;
function GetValue(Index: LongInt): Integer;
procedure SetValue(Index: LongInt; Value:
Integer);
public
constructor Create;
destructor Destroy; override;
function Add(const I: Integer): LongInt;
procedure Insert(Index: LongInt; const
I: Integer);
procedure Delete(Index: LongInt);
procedure Clear;
property Count: LongInt read FCount;
property Value[Index: LongInt]: Integer
read GetValue write SetValue; default;
end;
implementation
constructor TIntList.Create;
begin
inherited Create;
FCount := 0;
ReAllocMem(FInteger, (FCount + 1) * SizeOf(Integer));
end;
destructor TIntList.Destroy;
begin
ReAllocMem(FInteger, 0);
inherited Destroy;
end;
function TIntList.GetValue(Index: LongInt): Integer;
begin
if (not Assigned(Self)) or (Index < 0)
or (Index >= FCount) then
begin
MessageBox(0, PChar('Index außerhalb des zulässigen
Bereichs.'), PChar('Information'), MB_OK+MB_ICONINFORMATION);
Exit;
end;
Result := FInteger^[Index];
end;
procedure TIntList.SetValue(Index: LongInt; Value: Integer);
begin
if (not Assigned(Self)) or (Index < 0)
or (Index >= FCount) then
begin
MessageBox(0, PChar('Index außerhalb des zulässigen
Bereichs.'), PChar('Information'), MB_OK+MB_ICONINFORMATION);
Exit;
end;
FInteger^[Index] := Value;
end;
function TIntList.Add(const I: Integer): LongInt;
begin
FInteger^[FCount]:=I;
Result:=FCount;
inc(FCount);
ReAllocMem(FInteger, (FCount + 1) * SizeOf(Integer));
end;
procedure TIntList.Insert(Index: LongInt; const
I: Integer);
begin
if (Index < 0) or (Index > FCount) then
begin
MessageBox(0, PChar('Index außerhalb des zulässigen
Bereichs.'), PChar('Information'), MB_OK+MB_ICONINFORMATION);
Exit;
end;
inc(FCount);
ReAllocMem(FInteger, (FCount + 1) * SizeOf(Integer));
System.Move(FInteger^[Index], FInteger^[Index+1], (FCount-Index)*sizeof(Integer));
FInteger^[Index]:=I;
end;
procedure TIntList.Delete(Index: LongInt);
begin
if (Index < 0) or (Index >= FCount) then
begin
MessageBox(0, PChar('Index außerhalb des zulässigen
Bereichs.'), PChar('Information'), MB_OK+MB_ICONINFORMATION);
Exit;
end;
System.Move(FInteger^[Index+1], FInteger^[Index], (FCount-Index-1)*sizeof(Integer));
dec(FCount);
ReAllocMem(FInteger, (FCount + 1) * SizeOf(Integer));
end;
procedure TIntList.Clear;
begin
FCount := 0;
ReAllocMem(FInteger, (FCount + 1) * SizeOf(Integer));
end;