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

Last change on this file since 237 was 237, 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 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 if not (Self is TFile_Empty) then
69 begin
70 FDataFields := nil;
71 InitDataFields;
72 FEditor := nil;
73 end
74 else
75 begin
76 FEditor := nil;
77 end;
78end;
79
80
81procedure TFile.Free;
82begin
83 FDataFields.Free;
84end;
85
86
87function TFile.GetFieldByOffset(Offset: Integer): TDataField;
88begin
89 Result := FDataFields.FieldByOffset[Offset];
90end;
91
92
93function TFile.GetCaption: String;
94begin
95 Result := FFileInfo.Name;
96 if Result = '' then
97 Result := 'Unnamed';
98end;
99
100function TFile.GetChild(ID: Integer): TTreeElement;
101begin
102 Result := FDataFields.Child[ID];
103end;
104
105function TFile.GetChildCount: Integer;
106begin
107 if FDataFields <> nil then
108 Result := FDataFields.ChildCount;
109end;
110
111
112procedure TFile.InitDataFields;
113begin
114 if Assigned(FDataFields) then
115 Exit;
116 FFileStream := TMemoryStream.Create;
117 ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
118end;
119
120
121procedure TFile.InitEditor;
122begin
123 Exit;
124end;
125
126
127end.
Note: See TracBrowser for help on using the repository browser.