| 1 | Unit PCharList;
|
|---|
| 2 |
|
|---|
| 3 | Interface
|
|---|
| 4 |
|
|---|
| 5 | Uses
|
|---|
| 6 | Classes;
|
|---|
| 7 |
|
|---|
| 8 | Type
|
|---|
| 9 |
|
|---|
| 10 | // PCHar list class. It only stores the pointers; it does not copy or
|
|---|
| 11 | // dispose the strings themselves.
|
|---|
| 12 | TPCharList=class
|
|---|
| 13 | protected
|
|---|
| 14 | List: TList;
|
|---|
| 15 | public
|
|---|
| 16 | constructor Create;
|
|---|
| 17 | destructor Destroy; override;
|
|---|
| 18 | // Adds s to the list. Returns index of new item
|
|---|
| 19 | Function Add( S: PChar ): longint;
|
|---|
| 20 | // Returns string at index
|
|---|
| 21 | Function Get( index: longint ): PChar;
|
|---|
| 22 | Procedure Delete( index: longint );
|
|---|
| 23 |
|
|---|
| 24 | Procedure Put( index: longint; S: PChar );
|
|---|
| 25 |
|
|---|
| 26 | property Strings[ index: longint ]: PChar read Get write Put; default;
|
|---|
| 27 |
|
|---|
| 28 | Function Count: longint;
|
|---|
| 29 |
|
|---|
| 30 | procedure Clear;
|
|---|
| 31 | procedure Assign( NewText: TPCharList );
|
|---|
| 32 |
|
|---|
| 33 | Function IndexOf( SearchText: PChar ): longint;
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | Implementation
|
|---|
| 37 |
|
|---|
| 38 | Uses
|
|---|
| 39 | SysUtils;
|
|---|
| 40 |
|
|---|
| 41 | constructor TPCharList.Create;
|
|---|
| 42 | Begin
|
|---|
| 43 | List:= TList.Create;
|
|---|
| 44 | End;
|
|---|
| 45 |
|
|---|
| 46 | procedure TPCharList.Clear;
|
|---|
| 47 | begin
|
|---|
| 48 | while list.count>0 do
|
|---|
| 49 | Delete( 0 );
|
|---|
| 50 | end;
|
|---|
| 51 |
|
|---|
| 52 | destructor TPCharList.Destroy;
|
|---|
| 53 | Begin
|
|---|
| 54 | Clear;
|
|---|
| 55 | List.Destroy
|
|---|
| 56 | End;
|
|---|
| 57 |
|
|---|
| 58 | Function TPCharList.Add( S: PChar ): longint;
|
|---|
| 59 | Begin
|
|---|
| 60 | Result:= List.Add( S );
|
|---|
| 61 | End;
|
|---|
| 62 |
|
|---|
| 63 | Function TPCharList.Get( index: longint ): PChar;
|
|---|
| 64 | Begin
|
|---|
| 65 | Result:=List[ index ];
|
|---|
| 66 | End;
|
|---|
| 67 |
|
|---|
| 68 | Procedure TPCharList.Delete( index: longint );
|
|---|
| 69 | Begin
|
|---|
| 70 | List.Delete( index )
|
|---|
| 71 | End;
|
|---|
| 72 |
|
|---|
| 73 | Procedure TPCharList.Put( index: longint; S: PChar );
|
|---|
| 74 | Begin
|
|---|
| 75 | List[ index ]:=S;
|
|---|
| 76 | End;
|
|---|
| 77 |
|
|---|
| 78 | Function TPCharList.Count: longint;
|
|---|
| 79 | Begin
|
|---|
| 80 | Result:=List.Count;
|
|---|
| 81 | End;
|
|---|
| 82 |
|
|---|
| 83 | procedure TPCharList.Assign( NewText: TPCharList );
|
|---|
| 84 | var
|
|---|
| 85 | i: longint;
|
|---|
| 86 | begin
|
|---|
| 87 | Clear;
|
|---|
| 88 | for i:= 0 to NewText.Count - 1 do
|
|---|
| 89 | Add( StrNew( NewText[ i ] ) );
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | Function TPCharList.IndexOf( SearchText: PChar ): longint;
|
|---|
| 93 | var
|
|---|
| 94 | i: longint;
|
|---|
| 95 | begin
|
|---|
| 96 | for i:= 0 to List.Count - 1 do
|
|---|
| 97 | if StrIComp( Strings[ i ], SearchText ) = 0 then
|
|---|
| 98 | begin
|
|---|
| 99 | // found
|
|---|
| 100 | Result:= i;
|
|---|
| 101 | exit
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | Result:= -1;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | Initialization
|
|---|
| 108 | End.
|
|---|