?? ajfiledatetime.pas
字號:
///////////////////////////////////////////////////////////////////////
// //
// SoftSpot Software Component Library //
// Key Maker software component //
// //
// Copyright (c) 1996 - 2002 SoftSpot Software Ltd. //
// ALL RIGHTS RESERVED //
// //
// The entire contents of this file is protected by U.S. and //
// International Copyright Laws. Unauthorized reproduction, //
// reverse-engineering, and distribution of all or any portion of //
// the code contained in this file is strictly prohibited and may //
// result in severe civil and criminal penalties and will be //
// prosecuted to the maximum extent possible under the law. //
// //
// RESTRICTIONS //
// //
// THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED //
// FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE //
// COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE //
// AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT //
// AND PERMISSION FROM SOFTSPOT SOFTWARE LTD. //
// //
// CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON //
// ADDITIONAL RESTRICTIONS. //
// //
///////////////////////////////////////////////////////////////////////
unit ajFileDateTime;
{ -=< File Date Editor >=-
{
{ Copyright SoftSpot Software 2002 - All Rights Reserved
{
{ Author : Andrew J Jameson
{
{ Web site : www.softspotsoftware.com
{ e-mail : contact@softspotsoftware.com
{
{ Creation Date : 01 March 2002
{
{ Version : 1.00
{
{ Description : Date property editor for Key Maker. }
interface
uses
Windows, SysUtils;
type
TTimeType = (tCreation, tModified, tAccessed);
type
TajFileDateTime = class(TObject)
private
fError : boolean;
fChanged : boolean;
fFilename : string;
fFileInfo : TByHandleFileInformation;
fFileTimes : array[tCreation..tAccessed] of TSystemTime;
fNewFileTimes : array[tCreation..tAccessed] of TSystemTime;
protected
procedure SetfFilename (Value : string);
procedure GetFileInfo;
procedure GetFileDateTime;
function GetTime (index : TTimeType) : TDateTime;
procedure SetTime (index : TTimeType; Value : TDateTime);
public
constructor Create;
destructor Destroy; override;
procedure Update;
property Filename : string read fFilename write SetfFilename;
property CreationTime : TDateTime index tCreation read GetTime write SetTime;
property ModifiedTime : TDateTime index tModified read GetTime write SetTime;
property AccessedTime : TDateTime index tAccessed read GetTime write SetTime;
property Error : boolean read fError;
end;
implementation
{--------------------------------------------------------------------------------------------------}
{ TajFileDateTime }
{--------------------------------------------------------------------------------------------------}
constructor TajFileDateTime.Create;
begin
fError := false;
fChanged := false;
fFilename := ''
end; {constructor}
{--------------------------------------------------------------------------------------------------}
destructor TajFileDateTime.Destroy;
begin
end; {destructor}
{--------------------------------------------------------------------------------------------------}
procedure TajFileDateTime.SetfFilename(Value : string);
begin
fFilename := Value;
fError := false;
fChanged := false;
GetFileInfo;
GetFileDateTime;
end; {SetfFilename}
{--------------------------------------------------------------------------------------------------}
procedure TajFileDateTime.GetFileInfo;
var
Handle : THandle;
ReOpenBuff : TOfStruct;
begin
Handle := OpenFile(PChar(fFilename), ReOpenBuff, OF_READ);
if (Handle <> INVALID_HANDLE_VALUE) then begin
fError := not GetFileInformationByHandle(Handle, fFileInfo);
CloseHandle(Handle);
end else
fError := true;
end; {GetFileInfo}
{--------------------------------------------------------------------------------------------------}
procedure TajFileDateTime.GetFileDateTime;
var
lp1 : TTimeType;
begin
if not fError then
fError := not FileTimeToSystemTime(fFileInfo.ftCreationTime, fFileTimes[tCreation]);
if not fError then
fError := not FileTimeToSystemTime(fFileInfo.ftLastWriteTime, fFileTimes[tModified]);
if not fError then
fError := not FileTimeToSystemTime(fFileInfo.ftLastAccessTime, fFileTimes[tAccessed]);
for lp1 := tCreation to tAccessed do
fNewFileTimes[lp1] := fFileTimes[lp1];
end; {GetFileDateTime}
{--------------------------------------------------------------------------------------------------}
function Changed(Time1, Time2 : TSystemTime) : boolean;
begin
Result := (SystemTimeToDateTime(Time1) <> SystemTimeToDateTime(Time2));
end; {Changed}
{--------------------------------------------------------------------------------------------------}
procedure TajFileDateTime.Update;
var
Handle : THandle;
ReOpenBuff : TOfStruct;
NewFileTime : FILETIME;
begin
if not fError and fChanged then begin
Handle := OpenFile(PChar(fFilename), ReOpenBuff, OF_WRITE + OF_READWRITE);
if (Handle <> INVALID_HANDLE_VALUE) then begin
if not fError and Changed(fFileTimes[tCreation], fNewFileTimes[tCreation]) then begin
fError := not SystemTimeToFileTime(fNewFileTimes[tCreation], NewFileTime);
if not fError then
fError := not SetFileTime(Handle, @NewFileTime, nil, nil);
end; {if}
if not fError and Changed(fFileTimes[tModified], fNewFileTimes[tModified]) then begin
fError := not SystemTimeToFileTime(fNewFileTimes[tModified], NewFileTime);
if not fError then
fError := not SetFileTime(Handle, nil, nil, @NewFileTime);
end; {if}
if not fError and Changed(fFileTimes[tAccessed], fNewFileTimes[tAccessed]) then begin
fError := not SystemTimeToFileTime(fNewFileTimes[tAccessed], NewFileTime);
if not fError then
fError := not SetFileTime(Handle, nil, @NewFileTime, nil);
end; {if}
CloseHandle(Handle);
end else
fError := true;
end; {if}
end; {Update}
{--------------------------------------------------------------------------------------------------}
function TajFileDateTime.GetTime(index : TTimeType) : TDateTime;
begin
Result := SystemTimeToDateTime(fNewFileTimes[index]);
end; {GetTime}
{--------------------------------------------------------------------------------------------------}
procedure TajFileDateTime.SetTime(index : TTimeType; Value : TDateTime);
begin
if (Value <> GetTime(index)) then begin
fChanged := true;
DateTimeToSystemTime(Value, fNewFileTimes[index]);
end; {if}
end; {SetTime}
{--------------------------------------------------------------------------------------------------}
{ajFileDateTime}
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -