source: tags/1.3.0/UDataFile.pas

Last change on this file was 29, checked in by chronos, 2 years ago
  • Modified: Use fgl and generics instead of contnrs and TObjectList.
File size: 1.9 KB
Line 
1unit UDataFile;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, fgl;
9
10type
11 { TDataFile }
12
13 TDataFile = class
14 private
15 FFileName: string;
16 FModified: Boolean;
17 FOnModify: TNotifyEvent;
18 procedure SetFileName(AValue: string);
19 procedure SetModified(AValue: Boolean);
20 procedure DoOnModify;
21 public
22 function GetFileExt: string; virtual;
23 function GetFileName: string; virtual;
24 function GetFileFilter: string; virtual;
25 procedure LoadFromFile(FileName: string); virtual;
26 procedure SaveToFile(FileName: string); virtual;
27 constructor Create; virtual;
28 property FileName: string read FFileName write SetFileName;
29 property Modified: Boolean read FModified write SetModified;
30 property OnModify: TNotifyEvent read FOnModify write FOnModify;
31 end;
32
33 TDataFileClass = class of TDataFile;
34
35 TDataFiles = class(TFPGObjectList<TDataFile>)
36 end;
37
38
39implementation
40
41resourcestring
42 SDataFileName = 'File';
43 SAllFiles = 'All files';
44
45{ TDataFile }
46
47procedure TDataFile.SetModified(AValue: Boolean);
48begin
49 if FModified = AValue then Exit;
50 FModified := AValue;
51 DoOnModify;
52end;
53
54procedure TDataFile.DoOnModify;
55begin
56 if Assigned(FOnModify) then FOnModify(Self);
57end;
58
59function TDataFile.GetFileExt: string;
60begin
61 Result := '.dat';
62end;
63
64function TDataFile.GetFileName: string;
65begin
66 Result := SDataFileName;
67end;
68
69function TDataFile.GetFileFilter: string;
70begin
71 Result := SAllFiles + '|*.*';
72end;
73
74procedure TDataFile.LoadFromFile(FileName: string);
75begin
76 FModified := False;
77 Self.FileName := FileName;
78end;
79
80procedure TDataFile.SaveToFile(FileName: string);
81begin
82 Self.FileName := FileName;
83 FModified := False;
84end;
85
86constructor TDataFile.Create;
87begin
88 FileName := GetFileName + GetFileExt;
89end;
90
91procedure TDataFile.SetFileName(AValue: string);
92begin
93 if FFileName = AValue then Exit;
94 FFileName := AValue;
95end;
96
97
98end.
99
Note: See TracBrowser for help on using the repository browser.