1 | unit GenericFileList;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | type
|
---|
8 | TGFileList<T> = class(TGList<T>)
|
---|
9 | private
|
---|
10 | FFileName: string;
|
---|
11 | FMode: Word;
|
---|
12 | FHandle: THandle;
|
---|
13 | procedure SetFileName(const Value: string);
|
---|
14 | procedure SetMode(const Value: Word);
|
---|
15 | function GetOpenned: Boolean;
|
---|
16 | public
|
---|
17 | constructor Create; override;
|
---|
18 | destructor Destroy; override;
|
---|
19 | procedure Open;
|
---|
20 | procedure Close;
|
---|
21 | property FileName: string read FFileName write SetFileName;
|
---|
22 | property Mode: Word read FMode write SetMode;
|
---|
23 | property Openned: Boolean read GetOpenned;
|
---|
24 | end;
|
---|
25 |
|
---|
26 |
|
---|
27 | implementation
|
---|
28 |
|
---|
29 | constructor TGFileList<T>.Create;
|
---|
30 | begin
|
---|
31 | inherited;
|
---|
32 | FHandle := feInvalidHandle;
|
---|
33 | end;
|
---|
34 |
|
---|
35 | destructor TGFileList<T>.Destroy;
|
---|
36 | begin
|
---|
37 | Close;
|
---|
38 | inherited;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | procedure TGFileList<T>.Open;
|
---|
42 | begin
|
---|
43 | If (Mode and fmCreate) > 0 then
|
---|
44 | FHandle := FileCreate(FFileName, FMode, 438)
|
---|
45 | else
|
---|
46 | FHandle := FileOpen(FFileName, FMode);
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TGFileList<T>.Close;
|
---|
50 | begin
|
---|
51 | if FHandle <> feInvalidHandle then FileClose(FHandle);
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TGFileList<T>.SetFileName(const Value: string);
|
---|
55 | begin
|
---|
56 | if FFileName = Value then Exit;
|
---|
57 | FFileName := Value;
|
---|
58 | if FHandle <> feInvalidHandle then begin
|
---|
59 | Close;
|
---|
60 | Open;
|
---|
61 | end;
|
---|
62 | end;
|
---|
63 |
|
---|
64 | procedure TGFileList<T>.SetMode(const Value: Word);
|
---|
65 | begin
|
---|
66 | if FMode = Value then Exit;
|
---|
67 | FMode := Value;
|
---|
68 | if FHandle <> feInvalidHandle then begin
|
---|
69 | Close;
|
---|
70 | Open;
|
---|
71 | end;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | function TGFileListTGFileList.GetOpenned: Boolean;
|
---|
75 | begin
|
---|
76 | Result := FHandle <> feInvalidHandle;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | end.
|
---|