'Last Modified' bilgisini almak
Kullanımı: label1.Caption:=FileLastModified('c:\autoexec.bat' ) ;
~~~~~~~~~~~~~~~~~~~~~~~~~ function FileLastModified (const TheFile:
string): string; var FileH : THandle; LocalFT : TFileTime; DosFT :
DWORD; LastAccessedTime : TDateTime; FindData : TWin32FindData; begin
Result := ''; FileH := FindFirstFile(PChar(TheFile), FindData) ; if
FileH INVALID_HANDLE_VALUE then begin Windows.FindClose(Handle) ; if
(FindData.dwFileAttributes AND FILE_ATTRIBUTE_DIRECTORY) = 0 then begin
FileTimeToLocalFileTime (FindData.ftLastWriteTime,LocalFT) ;
FileTimeToDosDateTime (LocalFT,LongRec(DosFT).Hi,LongRec(DosFT).Lo) ;
LastAccessedTime := FileDateToDateTime(DosFT) ; Result :=
DateTimeToStr(LastAccessedTime) ; end; end; end; • Windows
Start-Documents bölümüne dosya eklemek
procedure AddtoDocMenu(fName : String) ;
begin
SHAddToRecentDocs(SHARD_PATH, PChar(fName)) ;
end;
• Form üzerine "crosshair" eklemek
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
{ I wrote this procedure with in this block for easy access, this one draws the cross hair}
Procedure DrawCross(AX,AY:Integer);
Begin
With Form1.Canvas Do
Begin
{ By putting pen mode to Xor will help to erase the previous cross hair }
Form1.Canvas.Pen.Mode:=pmNotXor;
MoveTo(Ax,0);
LineTo(Ax,Form1.Height);
MoveTo(0,AY);
LineTo(Form1.Width,AY);
End;
End;
begin
If Not FirstMove Then
DrawCross(OldX,OldY)
Else
FirstMove:=False;
DrawCross(X,Y);
Form1.Caption:='X : '+IntToStr(X)+' Y : '+IntToStr(Y);
OldX:=X;
OldY:=Y;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FirstMove:=True;
end;
• Komut satırından parametre okumak
procedure TForm1.FormCreate(Sender: TObject);
Var
I : Integer;
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('Parameters Count : '+IntToStr(ParamCount));
{ ParamCount - Returns the number of parameters passed on the command line. }
If ParamCount>0 Then
For I:=1 To ParamCount Do
{ ParamStr - Returns a specified parameter from the command-line. }
Memo1.Lines.Add('Parameter '+IntToStr(I)+' : '+ParamStr(I)) end;
• Disket sürücünün durumu
type
TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES);
function DriveState (driveletter: Char) : TDriveState;
var
mask: String[6];
sRec: TSearchRec;
oldMode: Cardinal;
retcode: Integer;
begin
oldMode: = SetErrorMode(SEM_FAILCRITICALERRORS);
mask:= '?:\*.*';
mask[1] := driveletter;
{$I-}
retcode := FindFirst (mask, faAnyfile, SRec);
FindClose(SRec);
{$I+}
case retcode of
0: Result := DSDISK_WITHFILES; { at least one file was found }
-18: Result := DSEMPTYDISK; { no files, but disk is ok }
-21, -3: Result := DSNODISK; { DOS ERRORNOTREADY in WinNT,
ERRORPATH_NOTFOUND in 3.1 }
else
Result := DSUNFORMATTEDDISK; { unformatted disk in drive }
end;
SetErrorMode(oldMode);
end; { DriveState }
• Geri Dönüşüm Kutusuna Dosya Göndermek
procedure RecycleFile(s : string);
var
SHFileOpStruct : TSHFileOpStruct;
begin
with SHFileOpStruct do
begin
Wnd := 0;
wFunc := FO_DELETE; // we want to delete a file...
pFrom := PChar(s+#0+#0); //... this file ...
pTo := nil;
fFlags := FOF_ALLOWUNDO; //... able to "Undo" (recycle)
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(SHFileOpStruct); // to the Recycle Bin
end;
Kullanımı: label1.Caption:=FileLastModified('c:\autoexec.bat' ) ;
~~~~~~~~~~~~~~~~~~~~~~~~~ function FileLastModified (const TheFile:
string): string; var FileH : THandle; LocalFT : TFileTime; DosFT :
DWORD; LastAccessedTime : TDateTime; FindData : TWin32FindData; begin
Result := ''; FileH := FindFirstFile(PChar(TheFile), FindData) ; if
FileH INVALID_HANDLE_VALUE then begin Windows.FindClose(Handle) ; if
(FindData.dwFileAttributes AND FILE_ATTRIBUTE_DIRECTORY) = 0 then begin
FileTimeToLocalFileTime (FindData.ftLastWriteTime,LocalFT) ;
FileTimeToDosDateTime (LocalFT,LongRec(DosFT).Hi,LongRec(DosFT).Lo) ;
LastAccessedTime := FileDateToDateTime(DosFT) ; Result :=
DateTimeToStr(LastAccessedTime) ; end; end; end; • Windows
Start-Documents bölümüne dosya eklemek
procedure AddtoDocMenu(fName : String) ;
begin
SHAddToRecentDocs(SHARD_PATH, PChar(fName)) ;
end;
• Form üzerine "crosshair" eklemek
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
{ I wrote this procedure with in this block for easy access, this one draws the cross hair}
Procedure DrawCross(AX,AY:Integer);
Begin
With Form1.Canvas Do
Begin
{ By putting pen mode to Xor will help to erase the previous cross hair }
Form1.Canvas.Pen.Mode:=pmNotXor;
MoveTo(Ax,0);
LineTo(Ax,Form1.Height);
MoveTo(0,AY);
LineTo(Form1.Width,AY);
End;
End;
begin
If Not FirstMove Then
DrawCross(OldX,OldY)
Else
FirstMove:=False;
DrawCross(X,Y);
Form1.Caption:='X : '+IntToStr(X)+' Y : '+IntToStr(Y);
OldX:=X;
OldY:=Y;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FirstMove:=True;
end;
• Komut satırından parametre okumak
procedure TForm1.FormCreate(Sender: TObject);
Var
I : Integer;
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('Parameters Count : '+IntToStr(ParamCount));
{ ParamCount - Returns the number of parameters passed on the command line. }
If ParamCount>0 Then
For I:=1 To ParamCount Do
{ ParamStr - Returns a specified parameter from the command-line. }
Memo1.Lines.Add('Parameter '+IntToStr(I)+' : '+ParamStr(I)) end;
• Disket sürücünün durumu
type
TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES);
function DriveState (driveletter: Char) : TDriveState;
var
mask: String[6];
sRec: TSearchRec;
oldMode: Cardinal;
retcode: Integer;
begin
oldMode: = SetErrorMode(SEM_FAILCRITICALERRORS);
mask:= '?:\*.*';
mask[1] := driveletter;
{$I-}
retcode := FindFirst (mask, faAnyfile, SRec);
FindClose(SRec);
{$I+}
case retcode of
0: Result := DSDISK_WITHFILES; { at least one file was found }
-18: Result := DSEMPTYDISK; { no files, but disk is ok }
-21, -3: Result := DSNODISK; { DOS ERRORNOTREADY in WinNT,
ERRORPATH_NOTFOUND in 3.1 }
else
Result := DSUNFORMATTEDDISK; { unformatted disk in drive }
end;
SetErrorMode(oldMode);
end; { DriveState }
• Geri Dönüşüm Kutusuna Dosya Göndermek
procedure RecycleFile(s : string);
var
SHFileOpStruct : TSHFileOpStruct;
begin
with SHFileOpStruct do
begin
Wnd := 0;
wFunc := FO_DELETE; // we want to delete a file...
pFrom := PChar(s+#0+#0); //... this file ...
pTo := nil;
fFlags := FOF_ALLOWUNDO; //... able to "Undo" (recycle)
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(SHFileOpStruct); // to the Recycle Bin
end;