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