sábado, 5 de setembro de 2009

Mostrando a lista de último acesso dos arquivos abertos

Unit Uultimoacesso;
{object Form1: TForm1
Left = 230
Top = 186
Width = 435
Height = 167
Caption = 'Ultimo Acesso'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Arial'
Font.Style = []
PixelsPerInch = 96
TextHeight = 18
object Label1: TLabel
Left = 6
Top = 11
Width = 53
Height = 18
Caption = 'Arquivo'
end
object Label2: TLabel
Left = 6
Top = 58
Width = 101
Height = 18
Caption = 'Último Acesso'
end
object EdArquivo: TEdit
Left = 6
Top = 28
Width = 281
Height = 26
TabOrder = 0
end
object BtSeleciona: TButton
Left = 226
Top = 82
Width = 87
Height = 31
Caption = 'Seleciona'
TabOrder = 1
OnClick = BtSelecionaClick
end
object EdUltimoAcesso: TEdit
Left = 6
Top = 82
Width = 204
Height = 26
TabOrder = 2
end
object ODSelecionaArquivo: TOpenDialog
Left = 352
Top = 8
end
end
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
EdArquivo: TEdit;
BtSeleciona: TButton;
Label1: TLabel;
Label2: TLabel;
EdUltimoAcesso: TEdit;
ODSelecionaArquivo: TOpenDialog;
procedure BtSelecionaClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.BtSelecionaClick(Sender: TObject);
var
FileHandle : THandle;
LocalFileTime : TFileTime;
DosFileTime : DWORD;
LastAccessdTime : TDateTime;
FindData : TWin32FindData;
NomeArquivo : array[0..255] of char;
begin
if OdSelecionaArquivo.Execute then
begin
EdArquivo.Text := OdSelecionaArquivo.FileName;
StrPCopy(NomeArquivo,OdSelecionaArquivo.FileName);
FileHandle := FindFirstFile(NomeArquivo, FindData);
if FileHandle = INVALID_HANDLE_VALUE then
begin
Windows.FindClose(Handle);
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
FileTimetoLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime, LongRec(DosFileTime).Hi, LongRec(DosFileTime).Lo);
LastAccessdTime := FileDateToDateTime(DosFileTime);
EdUltimoAcesso.Text := DateTimeToStr(LastAccessdTime);
end;
end;
end;
end;
end.

Nenhum comentário:

Postar um comentário