I'm using the Win32 api to get date and time of a file. I have a LPSYSTEMTIME structure, and I'm trying to print its wYear variable.
I've got a function (GetFileDate):
function GetFileDate : LPSYSTEMTIME
var
CheckFile: Long;
FileTime: LPFILETIME;
FileTimeReturn: LPFILETIME;
SystemTimeReturn: LPSYSTEMTIME;
begin
CheckFile := CreateFile(PChar('main.pas'), GENERIC_READ, FILE_SHARE_READ, NIL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
GetFileTime(CheckFile, FileTime, NIL, NIL);
FileTimeToLocalFileTime(FileTime, FileTimeReturn);
FileTimeToSystemTime(FileTimeReturn, SystemTimeReturn);
GetFileDate := SystemTimeReturn;
end;
But when I do this...
begin
Write(GetFileDate.wYear);
end.
It spits back
main.pas(22,20) Error: Illegal qualifier main.pas(22,20) Fatal: Syntax error, ")" expected but "identifier WYEAR" found Fatal: Compilation aborted
Any help on this?
LPSYSTEMTIME
is a pointer to aSYSTEMTIME
structure. Try using the^
operator to dereference that pointer, eg:Or:
With that said, aside from the fact that you are not doing any error handling at all, your
GetFileDate()
implementation is passing the wrong parameter values to the various API functions. That code should not even compile, let alone run correctly.Try this instead:
Alternatively, I would suggest using
FindFirstFile()
instead ofCreateFile()
so you do not have to open the file just to get its date. The filesystem can supply that information, eg: