TDosTime=Record<br> Hour : Byte;<br> Minutes : Byte;<br> seconds : Byte;<br> end;<br><br> TDosDate = Record<br> Year : Word;<br> Month : Byte;<br> Day : Byte;<br> end;<br><br>var<br> Form1: TForm1;<br> hFile: THandle; // a handle to the opened file<br><br>implementation<br><br>{this function provides a convenient way to convert a<br><br> Dos time into its component parts}<br>function ConvertDosTimeToSystemTime(FileDosTime: WORD): TDosTime;<br>var<br> DosTime: TDosTime;<br>begin<br> DosTime.Seconds := (FileDosTime and $1F) * 2;<br> DosTime.Minutes := (FileDosTime and $7E0) shr 5;<br> DosTime.Hour := (FileDosTime and $F800) shr 11;<br> Result := DosTime;<br>end;<br><br>{this function provides a convenient way to convert a<br> Dos date into its component parts}<br><br>function ConvertDosDateToSystemDate(FileDosDate: WORD): TDosDate;<br>var<br> DosDate: TDosDate;<br>begin<br> DosDate.Day := FileDosDate and $1F;<br> DosDate.Month := FileDosDate and $1E0 shr 5;<br> DosDate.Year := (FileDosDate and $FE00) shr 9 + 1980;<br> Result := DosDate;<br>end;<br><br>procedure TForm1.SpeedButton2Click(Sender: TObject);<br>var<br> Security: TSecurityAttributes; // attributes for the opened file<br><br> FileName: PChar; // holds the filename<br> WriteTime, LocalTime: TFILETIME; // holds file times<br> DosDate, DosTime: WORD; // holds the Dos date and time<br> infoDosTime: TDosTime; // holds Dos time information<br> infoDosDate: TDosDate; // holds Dos date information<br> SystemTime: TSystemTime; // holds the last modification time<br><br>begin<br> {setup the security attributes for the opened file}<br> Security.nLength := SizeOf(TSecurityAttributes);<br> Security.lpSecurityDescriptor := nil;<br> Security.bInheritHandle := FALSE;<br><br> {display the open dialog box}<br> if OpenDialog1.Execute then<br> begin<br> {display the selected filename...}<br> FileName := PChar(OpenDialog1.FileName);<br> StatusBar1.SimpleText := FileName;<br><br> {...and open it}<br><br> hFile := CreateFile(PChar(FileName),GENERIC_READ or GENERIC_WRITE,<br> FILE_SHARE_READ or FILE_SHARE_WRITE, @Security,<br> OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);<br><br> {if there was an error, show a message}<br> if hFile = INVALID_HANDLE_VALUE then<br> begin<br> ShowMessage('Error Opening File');<br> Exit;<br> end;<br> end;<br><br> {retrieve the last modification time}<br><br> GetFileTime(hFile, nil, nil, @WriteTime);<br><br> {convert the time to local file time}<br> FileTimeToLocalFileTime(WriteTime, LocalTime);<br><br> {finally, convert the time to the system time, so that it<br> will match the file time displayed in the Explorer}<br> FileTimeToSystemTime(LocalTime, SystemTime);<br><br> {convert the file time into Dos date and time components...}<br> FileTimeToDosDateTime(LocalTime, DosDate, DosTime);<br><br> {...and convert it back}<br><br> if not DosDateTimeToFileTime(DosDate, DosTime, LocalTime) then<br> ShowMessage ('An error occured when converting Dos date and time back to'+<br> ' file time.');<br><br> {break out the component parts of the Dos date and time for easy display}<br> infoDosTime := ConvertDosTimeToSystemTime(DosTime);<br> infoDosDate := ConvertDosDateToSystemDate(DosDate);<br><br> with infoDosTime do<br> Edit1.Text := ComboBox1.Items[infoDosDate.Month - 1]+ ' ' +<br><br> IntToStr(infoDosDate.Day) + ',' +<br> IntToStr(infoDosDate.Year) + ' ' +<br> IntToStr(Hour) + ':' +<br> IntToStr(Minutes) + ':' +<br> IntToStr(Seconds) ;<br><br> {indicate the time of day}<br> case SystemTime.WHour of<br> 12 : Label1.Caption := 'PM';<br> 13..24 : begin<br> Label1.Caption := 'PM';<br> SystemTime.wHour:=SystemTime.wHour - 12;<br><br> end;<br> 0 : SystemTime.wHour:= 12;<br> else<br> Label1.Caption := 'AM';<br> end;<br><br> {display the last modification time of the file}<br> SpinEdit1.Value := SystemTime.wYear;<br> SpinEdit2.Value := SystemTime.wHour;<br> SpinEdit3.Value := SystemTime.wMinute;<br> SpinEdit4.Value := SystemTime.wSecond;<br> ComboBox1.ItemIndex := SystemTime.wMonth - 1;<br> Calendar1.Month := SystemTime.wMonth;<br> Calendar1.Day := SystemTime.wDay;<br><br>end;<br><br>procedure TForm1.SpeedButton3Click(Sender: TObject);<br>var<br> FileTime, LocalFileTime: TFileTime; // holds file times<br> SystemTime: TSystemTime; // holds system time information<br>begin<br> {prepare the time information from the values set by the user}<br> SystemTime.wHour := SpinEdit2.Value;<br><br> if (Label1.Caption = 'PM') and (SystemTime.wHour < 12) then<br> SystemTime.wHour := SystemTime.wHour + 12;<br><br> SystemTime.wMinute := SpinEdit3.Value;<br> SystemTime.wSecond := SpinEdit4.Value;<br> SystemTime.wYear := SpinEdit1.Value;<br> SystemTime.wMonth := ComboBox1.ItemIndex + 1;<br> SystemTime.wDay := Calendar1.Day;<br><br> {convert the system time to a local file time}<br> SystemTimeToFileTime(SystemTime,LocalFileTime);<br><br> {convert the local file time to a file time that the file system understands}<br> LocalFileTimeToFileTime(LocalFileTime,FileTime);<br><br> {use this time to set the last modification time which shows<br> up in the Explorer}<br> SetFileTime(hFile, nil, nil, @FileTime);<br>end;<br>