source: Generics/NativeGenerics/Generic/GenericFileList.pas

Last change on this file was 496, checked in by chronos, 7 years ago
  • Modified: New native generics classes working under FPC 3.0 transformed from TemplateGenerics package.
File size: 1.6 KB
Line 
1unit GenericFileList;
2
3{$mode delphi}
4
5interface
6
7type
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
27implementation
28
29constructor TGFileList<T>.Create;
30begin
31 inherited;
32 FHandle := feInvalidHandle;
33end;
34
35destructor TGFileList<T>.Destroy;
36begin
37 Close;
38 inherited;
39end;
40
41procedure TGFileList<T>.Open;
42begin
43 If (Mode and fmCreate) > 0 then
44 FHandle := FileCreate(FFileName, FMode, 438)
45 else
46 FHandle := FileOpen(FFileName, FMode);
47end;
48
49procedure TGFileList<T>.Close;
50begin
51 if FHandle <> feInvalidHandle then FileClose(FHandle);
52end;
53
54procedure TGFileList<T>.SetFileName(const Value: string);
55begin
56 if FFileName = Value then Exit;
57 FFileName := Value;
58 if FHandle <> feInvalidHandle then begin
59 Close;
60 Open;
61 end;
62end;
63
64procedure TGFileList<T>.SetMode(const Value: Word);
65begin
66 if FMode = Value then Exit;
67 FMode := Value;
68 if FHandle <> feInvalidHandle then begin
69 Close;
70 Open;
71 end;
72end;
73
74function TGFileListTGFileList.GetOpenned: Boolean;
75begin
76 Result := FHandle <> feInvalidHandle;
77end;
78
79end.
Note: See TracBrowser for help on using the repository browser.