Changeset 233 for oup/current/FileClasses/_Extensions.pas
- Timestamp:
- Jun 29, 2007, 2:38:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/FileClasses/_Extensions.pas
r231 r233 4 4 5 5 uses 6 _FileTypes ;6 _FileTypes, _TreeElement; 7 7 8 8 type 9 TExtension = class 9 TExtension = class(TTreeElement) 10 function GetChildCount: Integer; override; 11 function GetChild(ID: Integer): TTreeElement; override; 12 function GetCaption: String; override; 10 13 private 11 FConnectionID: Integer;12 14 FExt: String; 13 15 FFiles: array of Integer; 14 function GetFile(ID: Integer): Integer;15 function GetFileCount: Integer;16 16 public 17 17 constructor Create(ConnectionID: Integer; Ext: String); virtual; 18 18 procedure InitList; 19 property Ext: String read FExt;20 property Files[ID: Integer]: Integer read GetFile;21 property FileCount: Integer read GetFileCount;22 19 end; 23 20 24 TExtensions = array of TExtension; 25 21 TExtensions = class(TTreeElement) 22 function GetChildCount: Integer; override; 23 function GetChild(ID: Integer): TTreeElement; override; 24 function GetCaption: String; override; 25 private 26 FExtensions: array of TExtension; 27 public 28 constructor Create(DataAccess: TObject; ConnectionID: Integer); 29 function GetExt(Ext: String): TExtension; 30 procedure AddExt(Ext: String); 31 end; 32 26 33 27 34 … … 29 36 30 37 uses 31 Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs ;38 Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager; 32 39 33 40 { TExtension } … … 39 46 end; 40 47 41 function TExtension.Get File(ID: Integer): Integer;48 function TExtension.GetCaption: String; 42 49 begin 43 Result := F Files[ID];50 Result := FExt; 44 51 end; 45 52 46 function TExtension.GetFileCount: Integer; 53 function TExtension.GetChild(ID: Integer): TTreeElement; 54 var 55 Meta: TMetaManager; 56 begin 57 Meta := ConManager.Connection[FConnectionID].MetaData; 58 Meta.InitFile(FFiles[ID]); 59 Result := Meta.FileById[FFiles[ID]]; 60 end; 61 62 function TExtension.GetChildCount: Integer; 47 63 begin 48 64 Result := Length(FFiles); … … 57 73 begin 58 74 files := TStringList.Create; 59 files := ConManager.Connection[FConnectionID].GetFilesList( Ext, '', False, ST_NameAsc);75 files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc); 60 76 if files.Count > 0 then 61 77 begin … … 74 90 end; 75 91 92 93 { TExtensions } 94 95 function TExtensions.GetCaption: String; 96 begin 97 Result := ''; 98 end; 99 100 function TExtensions.GetChild(ID: Integer): TTreeElement; 101 begin 102 Result := FExtensions[ID]; 103 end; 104 105 function TExtensions.GetChildCount: Integer; 106 begin 107 Result := Length(FExtensions); 108 end; 109 110 constructor TExtensions.Create(DataAccess: TObject; ConnectionID: Integer); 111 var 112 files: TStrings; 113 i: Integer; 114 fid: Integer; 115 finfo: TFileInfo; 116 begin 117 FConnectionID := ConnectionID; 118 files := TStringList.Create; 119 files := TDataAccess(DataAccess).GetFilesList('', '', False, ST_IDAsc); 120 SetLength(FExtensions, 0); 121 if files.Count > 0 then 122 begin 123 for i := 0 to files.Count - 1 do 124 begin 125 fid := StrToInt(MidStr(files.Strings[i], 1, 5)); 126 finfo := TDataAccess(DataAccess).GetFileInfo(fid); 127 if Length(finfo.Name) > 0 then 128 if not Assigned(GetExt(finfo.Extension)) then 129 AddExt(finfo.Extension); 130 end; 131 end; 132 files.Free; 133 end; 134 135 136 function TExtensions.GetExt(Ext: String): TExtension; 137 var 138 i: Integer; 139 begin 140 Result := nil; 141 if Length(FExtensions) > 0 then 142 for i := 0 to High(FExtensions) do 143 if FExtensions[i].GetCaption = Ext then 144 begin 145 Result := FExtensions[i]; 146 Break; 147 end; 148 end; 149 150 procedure TExtensions.AddExt(Ext: String); 151 var 152 i: Integer; 153 begin 154 SetLength(FExtensions, Length(FExtensions) + 1); 155 for i := High(FExtensions) downto 1 do 156 begin 157 if FExtensions[i-1].GetCaption < Ext then 158 begin 159 FExtensions[i] := TExtension.Create(FConnectionID, Ext); 160 Break; 161 end 162 else 163 FExtensions[i] := FExtensions[i-1]; 164 end; 165 if i = 0 then 166 FExtensions[0] := TExtension.Create(FConnectionID, Ext); 167 end; 168 169 170 76 171 end.
Note:
See TracChangeset
for help on using the changeset viewer.