source: oup/current/FileClasses/_FileTypes.pas@ 234

Last change on this file since 234 was 233, checked in by alloc, 17 years ago
File size: 2.6 KB
Line 
1unit _FileTypes;
2
3interface
4
5uses
6 TypeDefs, _DataTypes, _TreeElement, Classes, Forms;
7
8
9type
10 TFile = class(TTreeElement)
11 function GetChildCount: Integer; override;
12 function GetChild(ID: Integer): TTreeElement; override;
13 function GetCaption: String; override;
14 private
15 FConnectionID: Integer;
16 protected
17 FFileInfo: TFileInfo;
18 FFileStream: TMemoryStream;
19
20 FCached: Boolean;
21 FChanged: Boolean;
22
23 FDataFields: TBlock;
24
25 FEditor: TFrame;
26 FOpened: Boolean;
27
28 function GetFieldByOffset(Offset: Integer): TDataField;
29 published
30 public
31 constructor Create(ConnectionID, FileID: Integer); virtual;
32 procedure Free;
33
34 procedure InitDataFields; virtual;
35 procedure InitEditor; virtual;
36
37 property FileStream: TMemoryStream read FFileStream;
38 property FileInfo: TFileInfo read FFileInfo;
39 property ConnectionID: Integer read FConnectionID;
40
41 property Cached: Boolean read FCached;
42 property Changed: Boolean read FChanged write FChanged;
43
44 property Editor: TFrame read FEditor;
45 property Opened: Boolean read FOpened write FOpened;
46
47 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
48 end;
49
50
51 TFileType = class of TFile;
52
53
54
55implementation
56
57uses
58 DatLinks, RawList, ConnectionManager, Dialogs, _MetaTypes, _MetaManager;
59
60{ TFileType }
61
62constructor TFile.Create(ConnectionID, FileID: Integer);
63begin
64 FConnectionID := ConnectionID;
65 FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
66
67 FCached := False;
68 FChanged := False;
69
70 if not (Self is TFile_Empty) then
71 begin
72 FDataFields := nil;
73 InitDataFields;
74 FEditor := nil;
75 end
76 else
77 begin
78 FEditor := nil;
79 end;
80end;
81
82
83procedure TFile.Free;
84begin
85 FDataFields.Free;
86end;
87
88
89function TFile.GetFieldByOffset(Offset: Integer): TDataField;
90begin
91 Result := FDataFields.FieldByOffset[Offset];
92end;
93
94
95function TFile.GetCaption: String;
96begin
97 Result := FFileInfo.Name;
98 if Result = '' then
99 Result := 'Unnamed';
100end;
101
102function TFile.GetChild(ID: Integer): TTreeElement;
103begin
104 Result := FDataFields.Child[ID];
105end;
106
107function TFile.GetChildCount: Integer;
108begin
109 if FDataFields <> nil then
110 Result := FDataFields.ChildCount;
111end;
112
113
114procedure TFile.InitDataFields;
115begin
116 if Assigned(FDataFields) then
117 Exit;
118 FFileStream := TMemoryStream.Create;
119 ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
120end;
121
122
123procedure TFile.InitEditor;
124begin
125 Exit;
126end;
127
128
129end.
Note: See TracBrowser for help on using the repository browser.