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

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