Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.063 Beiträge
Delphi 12 Athens
|
Re: Funktionsoptimierung
30. Nov 2009, 12:20
immer wieder dieses böse FindClose
Delphi-Quellcode:
procedure BuildFileList(aSourceDir, aDestDir: string; aSource, aFiles:
TStringList; aMaxFileAge: Integer); cdecl;
var
sFileName: string;
hSource, hDest: THandle;
rSourceFindData, rDestFindData: TWIN32FindData;
ftCreationTime, ftLastWriteTime, ftLastWriteTimeDest: TFileTime;
begin
aSourceDir := IncludeTrailingPathDelimiter(aSourceDir);
aDestDir := IncludeTrailingPathDelimiter(aDestDir);
aFiles.BeginUpdate;
try
for sFileName in aSource do
begin
hSource := FindFirstFile(PChar(aSourceDir + sFileName), rSourceFindData);
Windows.FindClose(hSource);
hDest := FindFirstFile(PChar(aDestDir + sFileName), rDestFindData);
Windows.FindClose(hDest);
FileTimeToLocalFileTime(rSourceFindData.ftCreationTime, ftCreationTime);
FileTimeToLocalFileTime(rSourceFindData.ftLastWriteTime, ftLastWriteTime);
FileTimeToLocalFileTime(rDestFindData.ftLastWriteTime, ftLastWriteTimeDest);
if (hSource <> INVALID_HANDLE_VALUE)
and (rSourceFindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0)
and ((aDestDir = INVALID_HANDLE_VALUE)
or ((aMaxFileAge = 0) and (ftLastWriteTime > ftLastWriteTimeDest))
or ((aMaxFileAge <> 0)
and ((DaysBetween(FileTimeToDateTime(ftCreationTime), Date) <= aMaxFileAge)
or (DaysBetween(FileTimeToDateTime(ftLastWriteTime), Date) <= aMaxFileAge)))) then
aFiles.Add(aSourceDir + sFileName);
end;
aFiles.Sort;
finally
aFiles.EndUpdate;
end;
end;
Neuste Erkenntnis:
Seit Pos einen dritten Parameter hat,
wird PoSex im Delphi viel seltener praktiziert.
|
|
Zitat
|