Browse Source

* FileSetDate now working on Win, see #7837
* FileSetDate more Delphi compatible

git-svn-id: trunk@5824 -

florian 18 năm trước cách đây
mục cha
commit
35fdb22b91

+ 1 - 0
.gitattributes

@@ -6895,6 +6895,7 @@ tests/test/units/system/ttrunc.pp svneol=native#text/plain
 tests/test/units/sysutils/execansi.pp svneol=native#text/plain
 tests/test/units/sysutils/execedbya.pp svneol=native#text/plain
 tests/test/units/sysutils/extractquote.pp svneol=native#text/plain
+tests/test/units/sysutils/tfile1.pp svneol=native#text/plain
 tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
 tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
 tests/test/uprec6.pp svneol=native#text/plain

+ 3 - 4
rtl/objpas/sysutils/sysutils.inc

@@ -59,12 +59,11 @@
 
   {$ifndef OS_FILESETDATEBYNAME}
   Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
-
   Var
     fd : THandle;
-
   begin
-    fd:=FileOpen(FileName,fmOpenRead);
+    { at least windows requires fmOpenWrite here }
+    fd:=FileOpen(FileName,fmOpenWrite);
     If (Fd<>feInvalidHandle) then
       try
         Result:=FileSetDate(fd,Age);
@@ -72,7 +71,7 @@
         FileClose(fd);
       end
     else
-      Result:=Fd;
+      Result:=fd;
   end;
   {$endif}
 

+ 1 - 1
rtl/win/sysutils.pp

@@ -409,7 +409,7 @@ Var
 begin
   Result := 0;
   if DosToWinTime(Age,FT) and
-    SetFileTime(Handle, ft, ft, FT) then
+    SetFileTime(Handle, nil, nil, @FT) then
     Exit;
   Result := GetLastError;
 end;

+ 34 - 0
tests/test/units/sysutils/tfile1.pp

@@ -0,0 +1,34 @@
+PROGRAM Test;
+
+USES
+  SysUtils;
+
+procedure do_error(l : longint);
+  begin
+     writeln('Error near number ',l);
+     halt(1);
+  end;
+
+VAR
+  dateTime: TDateTime;
+  f : file;
+
+BEGIN
+  if FileExists('datetest.dat') then
+    begin
+      Assign(f,'datetest.dat');
+      Erase(f);
+    end;
+
+  if FileExists('datetest.dat') then
+    do_error(1000);
+
+  FileClose(FileCreate('datetest.dat'));
+
+  if not(FileExists('datetest.dat')) then
+    do_error(1001);
+
+  dateTime := IncMonth(Now, -1);
+  if FileSetDate('datetest.dat', DateTimeToFileDate(dateTime))<>0 then
+    do_error(1002);
+END.