TSystemTime Error

Discussion and questions about programming with Ultibo.
johan
Posts: 5
Joined: Thu Sep 13, 2018 2:37 am

TSystemTime Error

Postby johan » Tue Aug 06, 2019 1:06 am

hi i am johan

i want to get File Modified Date Time.

Code: Select all

uses
  Classes, SysUtils, fgl, Process, ultibo;

function GetFileDateTime(FilePath : String):TDateTime;
var
  SR: TSearchRec;
  LocalFileTime: TFileTime;
  ST : SystemTime;
  ST1 : TSystemTime;
  FT: TDateTime;
  msg, Path : String;
begin
  Path := FilePath.Replace(' ', '');

  ST := default(SystemTime);
  ST1 := default(TSystemTime);
  LocalFileTime := default(TFileTime);

  if FindFirst(Path, faAnyFile, SR) = 0 then
  begin
    if FileTimeToLocalFileTime(SR.FindData.ftLastWriteTime, LocalFileTime) then
    begin
      if FileTimeToSystemTime(LocalFileTime, ST1) then
       begin
         FT := SystemTimeToDateTime(ST1); //-Error
       end;
    end;
    SysUtils.FindClose(SR);
  end;

  Result := FT;

end;


"FT := SystemTimeToDateTime(ST1);" - Error
This is Error : Incompatible type for arg no. 1 : Got "_SYSTEMTIME", expected "TSystemTime"
How can use TSystemTime?
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: TSystemTime Error

Postby Ultibo » Tue Aug 06, 2019 10:50 am

johan wrote:This is Error : Incompatible type for arg no. 1 : Got "_SYSTEMTIME", expected "TSystemTime"
How can use TSystemTime?

Hello johan,

The current duplication of TSystemTime between the SysUtils and Timezone units is something we still need to do a little more work on in order to resolve it properly and we hope it will be possible to get this done soon.

In the meantime you can modify your function just a little bit and avoid the problem with TSystemTime by converting directly from TFileTIme to TDateTime, here's your function with the modification needed to make it work:

Code: Select all

function GetFileDateTime(FilePath : String):TDateTime;
var
  SR: TSearchRec;
  LocalFileTime: TFileTime;
  //ST : SystemTime;
  //ST1 : TSystemTime;
  FT: TDateTime;
  msg, Path : String;
begin
  Path := FilePath.Replace(' ', '');

  //ST := default(SystemTime);
  //ST1 := default(TSystemTime);
  LocalFileTime := default(TFileTime);

  if FindFirst(Path, faAnyFile, SR) = 0 then
  begin
    if FileTimeToLocalFileTime(SR.FindData.ftLastWriteTime, LocalFileTime) then
    begin
      FT := LocalFileTimeToDateTime(LocalFileTime);
      //if FileTimeToSystemTime(LocalFileTime, ST1) then
      // begin
      //   FT := SystemTimeToDateTime(ST1); //-Error
      // end;
    end;
    SysUtils.FindClose(SR);
  end;

  Result := FT;

end;

Hope that helps, let us know if you have any problems.


EDIT: As of Ultibo Core 2.0.715 we've resolved the duplication issue with TSystemTime so the original code in this thread now works
Ultibo.org | Make something amazing
https://ultibo.org
johan
Posts: 5
Joined: Thu Sep 13, 2018 2:37 am

Re: TSystemTime Error

Postby johan » Wed Aug 07, 2019 7:09 am

thank you

Return to “General”

Who is online

Users browsing this forum: No registered users and 44 guests