source: trunk/Library/PCharList.pas@ 413

Last change on this file since 413 was 394, checked in by RBRi, 9 years ago

+ copyright

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1Unit 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
8Interface
9
10Uses
11 Classes;
12
13Type
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
41Implementation
42
43Uses
44 SysUtils;
45
46constructor TPCharList.Create;
47Begin
48 List:= TList.Create;
49End;
50
51procedure TPCharList.Clear;
52begin
53 while list.count>0 do
54 Delete( 0 );
55end;
56
57destructor TPCharList.Destroy;
58Begin
59 Clear;
60 List.Destroy
61End;
62
63Function TPCharList.Add( S: PChar ): longint;
64Begin
65 Result:= List.Add( S );
66End;
67
68Function TPCharList.Get( index: longint ): PChar;
69Begin
70 Result:=List[ index ];
71End;
72
73Procedure TPCharList.Delete( index: longint );
74Begin
75 List.Delete( index )
76End;
77
78Procedure TPCharList.Put( index: longint; S: PChar );
79Begin
80 List[ index ]:=S;
81End;
82
83Function TPCharList.Count: longint;
84Begin
85 Result:=List.Count;
86End;
87
88procedure TPCharList.Assign( NewText: TPCharList );
89var
90 i: longint;
91begin
92 Clear;
93 for i:= 0 to NewText.Count - 1 do
94 Add( StrNew( NewText[ i ] ) );
95end;
96
97Function TPCharList.IndexOf( SearchText: PChar ): longint;
98var
99 i: longint;
100begin
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;
110end;
111
112Initialization
113End.
Note: See TracBrowser for help on using the repository browser.