📄 uatpdes.pas
字号:
{******************************************************************************************}
{ }
{ Universal Agent on demond SDK }
{ }
{ }
{ COPYRIGHT }
{ ========= }
{ The UA SDK (software) is Copyright (C) 2001-2003, by vinson zeng(曾胡龙). }
{ All rights reserved. }
{ The authors - vinson zeng (曾胡龙), }
{ exclusively own all copyrights to the Advanced Application }
{ Controls (AppControls) and all other products distributed by Utilmind Solutions(R). }
{ }
{ LIABILITY DISCLAIMER }
{ ==================== }
{ THIS SOFTWARE IS DISTRIBUTED "AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE }
{ OF MERCHANTABILITY OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
{ YOU USE IT AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, }
{ DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.}
{ }
{ RESTRICTIONS }
{ ============ }
{ You may not attempt to reverse compile, modify, }
{ translate or disassemble the software in whole or in part. }
{ You may not remove or modify any copyright notice or the method by which }
{ it may be invoked. }
{******************************************************************************************}
unit UATPDes;
interface
uses
Classes, SysUtils, {$IFDEF VER140}Variants, {$ENDIF}
Windows;
type
TUAList = class(TObject)
FList: array of TObject;
FCount: Integer;
FCapacity: Integer;
protected
function Get(Index: Integer): TObject;
procedure Grow; virtual;
procedure Put(Index: Integer; Item: TObject);
procedure SetCapacity(NewCapacity: Integer);
public
constructor Create;
destructor Destroy; override;
function Add(Item: TObject): Integer;
procedure Clear; virtual;
procedure Delete(Index: Integer);
function IndexOf(Item: TObject): Integer;
function Last: TObject;
function Remove(Item: TObject): Integer;
procedure Sort(Compare: TListSortCompare);
property Capacity: Integer read FCapacity write SetCapacity;
property Count: Integer read FCount;
property Items[Index: Integer]: TObject read Get write Put; default;
end;
TUADyMatrix = class(TUAList)
private
protected
public
end;
implementation
uses RTLConsts;
{ TUAList }
constructor TUAList.Create;
begin
inherited Create;
SetCapacity(10);
end;
destructor TUAList.Destroy;
begin
Clear;
inherited;
end;
procedure TUAList.Clear;
begin
FCount := 0;
SetCapacity(0);
end;
procedure TUAList.Delete(Index: Integer);
begin
if (Index < 0) or (Index >= FCount) then
TList.Error(@SListIndexError, Index);
Dec(FCount);
if Index < FCount then
System.Move(FList[Index + 1], FList[Index],
(FCount - Index) * SizeOf(Pointer));
end;
function TUAList.IndexOf(Item: TObject): Integer;
begin
Result := 0;
while (Result < FCount) and (FList[Result] <> Item) do
Inc(Result);
if Result = FCount then
Result := -1;
end;
function TUAList.Last: TObject;
begin
Result := Get(FCount - 1);
end;
function TUAList.Remove(Item: TObject): Integer;
begin
Result := IndexOf(Item);
if Result >= 0 then
Delete(Result);
end;
procedure QuickSort(SortList: array of TObject; L, R: Integer;
SCompare: TListSortCompare);
var
I, J: Integer;
P, T: TObject;
begin
repeat
I := L;
J := R;
P := SortList[(L + R) shr 1];
repeat
while SCompare(SortList[I], P) < 0 do
Inc(I);
while SCompare(SortList[J], P) > 0 do
Dec(J);
if I <= J then
begin
T := SortList[I];
SortList[I] := SortList[J];
SortList[J] := T;
Inc(I);
Dec(J);
end;
until I > J;
if L < J then
QuickSort(SortList, L, J, SCompare);
L := I;
until I >= R;
end;
procedure TUAList.Sort(Compare: TListSortCompare);
begin
if (FList <> nil) and (Count > 0) then
QuickSort(FList, 0, Count - 1, Compare);
end;
function TUAList.Add(Item: TObject): Integer;
begin
Result := FCount;
if Result = FCapacity then
Grow;
FList[Result] := Item;
Inc(FCount);
end;
function TUAList.Get(Index: Integer): TObject;
begin
if (Index < 0) or (Index >= FCount) then
TList.Error(@SListIndexError, Index);
Result := FList[Index];
end;
procedure TUAList.Grow;
var
Delta: Integer;
begin
if FCapacity > 64 then
Delta := FCapacity div 4
else
if FCapacity > 8 then
Delta := 16
else
Delta := 4;
SetCapacity(FCapacity + Delta);
end;
procedure TUAList.Put(Index: Integer; Item: TObject);
begin
if (Index < 0) or (Index >= FCount) then
TList.Error(@SListIndexError, Index);
FList[Index] := Item;
end;
procedure TUAList.SetCapacity(NewCapacity: Integer);
begin
if (NewCapacity < FCount) or (NewCapacity > MaxListSize) then
TList.Error(@SListCapacityError, NewCapacity);
if NewCapacity <> FCapacity then
begin
SetLength(FList, NewCapacity);
FCapacity := NewCapacity;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -