Changeset 157 for oup/current
- Timestamp:
- Apr 2, 2007, 1:47:18 AM (18 years ago)
- Location:
- oup/current
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/DataAccess/Access_OUP_ADB.pas
r156 r157 214 214 215 215 216 function CompareItems(List: TStringList; I1, I2: Integer): Integer;217 var218 fin: Boolean;219 pos: Integer;220 s1, s2: String;221 begin222 fin := False;223 s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1);224 s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1);225 pos := 1;226 Result := 0;227 repeat228 if Ord(s1[pos]) < Ord(s2[pos]) then229 begin230 Result := -1;231 fin := True;232 end233 else if Ord(s1[pos]) > Ord(s2[pos]) then234 begin235 Result := 1;236 fin := True;237 end;238 Inc(pos);239 until fin or (pos > Length(s1)) or (pos > Length(s2));240 241 if not fin then242 begin243 if pos > Length(s1) then244 Result := -1245 else246 Result := 1;247 end;248 end;249 250 216 function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String; 251 217 NoEmptyFiles: Boolean; SortType: TSortType): TStrings; … … 286 252 287 253 begin 288 list := TStringList.Create; 289 if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then 290 list.Sorted := False 291 else 254 if not (SortType in [ST_ExtNameAsc, ST_ExtNameDesc]) then 255 begin 256 list := TStringList.Create; 292 257 list.Sorted := True; 293 for i := 0 to GetFileCount - 1 do 294 begin 295 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and 296 ((Length(pattern) = 0) or 297 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then 298 begin 299 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then 258 for i := 0 to GetFileCount - 1 do 259 begin 260 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and 261 ((Length(pattern) = 0) or 262 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then 300 263 begin 301 id := FormatNumber(Fdat_files[i].ID, 5, '0'); 302 name := Fdat_files[i].Name; 303 extension := Fdat_files[i].Extension; 304 305 case SortType of 306 ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension); 307 ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension); 308 ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name); 309 ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id); 264 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then 265 begin 266 id := FormatNumber(Fdat_files[i].ID, 5, '0'); 267 name := Fdat_files[i].Name; 268 extension := Fdat_files[i].Extension; 269 270 case SortType of 271 ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension); 272 ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension); 273 ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name); 274 ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id); 275 end; 310 276 end; 311 277 end; 312 278 end; 313 end; 314 if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then 315 list.CustomSort(CompareItems); 316 if not Assigned(Result) then 317 Result := TStringList.Create; 318 if list.Count > 0 then 319 begin 320 fields := TStringList.Create; 321 if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then 322 for i := 0 to list.Count - 1 do 323 begin 324 getfields; 325 Result.Add(id + '-' + name + '.' + extension); 326 end 327 else 328 for i := list.Count - 1 downto 0 do 329 begin 330 getfields; 331 Result.Add(id + '-' + name + '.' + extension); 332 end; 333 fields.Free; 334 end; 335 list.Free; 279 if not Assigned(Result) then 280 Result := TStringList.Create; 281 if list.Count > 0 then 282 begin 283 fields := TStringList.Create; 284 if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then 285 for i := 0 to list.Count - 1 do 286 begin 287 getfields; 288 Result.Add(id + '-' + name + '.' + extension); 289 end 290 else 291 for i := list.Count - 1 downto 0 do 292 begin 293 getfields; 294 Result.Add(id + '-' + name + '.' + extension); 295 end; 296 fields.Free; 297 end; 298 list.Free; 299 end 300 else 301 begin 302 FQuery.SQL.Text := 'SELECT id, name, extension FROM datfiles ' + 303 'WHERE Length(name) > 0 ORDER BY extension ASC, name ASC;'; 304 FQuery.Open; 305 if not Assigned(Result) then 306 Result := TStringList.Create; 307 if FQuery.RecordCount > 0 then 308 begin 309 FQuery.First; 310 repeat 311 name := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') + 312 '-' + FQuery.FieldByName('name').AsString + '.' + 313 FQuery.FieldByName('extension').AsString; 314 if SortType = ST_ExtNameAsc then 315 Result.Add(name) 316 else 317 Result.Insert(0, name); 318 FQuery.Next; 319 until FQuery.EOF; 320 end; 321 FQuery.Close; 322 end; 336 323 end; 337 324
Note:
See TracChangeset
for help on using the changeset viewer.