Se si ha bisogno di salvare il cuntenuto di un URL oppure un vero e proprio file presente in rete avendo anche la possibilità di controllare come procede il download, bisogna usare l’action TDownLoadURL. Essa genera un evento OnDownloadProgress, che consente di tenere traccia dei byte scaricati.
Nota: bisogna includere la unit ExtActns nella uses.
(continua…)
Archivi per la categoria ‘Delphi’
Scaricare file dalla rete con delphi
14 set 2007
Calcolo della pasqua cristiana
20 ago 2007
Funzione che calcola il giorno di Pasqua.
function GetEaster(Year: Integer): TDate;
var y, m, d: Word;
G, I, J, C, H, L: Integer;
E: TDate;
begin
G := Year mod 19;
C := year div 100;
H := (C - C div 4 - (8*C+13) div 25 + 19*G + 15) mod 30;
I := H - (H div 28)*(1 - (H div 28)*(29 div (H + 1))*((21 - G) div 11));
J := (Year + Year div 4 + I + 2 - C + C div 4) mod 7;
L := I - J;
m := 3 + (L + 40) div 44;
d := L + 28 - 31*(m div 4);
y := Year;
E := EncodeDate(y, m, d);
while DayOfWeek(E) > 1 do
E := E + 1;
Result := E;
end;
{
Utilizzo:
var EasterDate: TDateTime;
...
EasterDate := GetEaster(2002);
}
Funzione che calcola il giorno di Pasqua.
function GetEaster(Year: Integer): TDate; var y, m, d: Word; G, I, J, C, H, L: Integer; E: TDate; begin G := Year mod 19; C := year div 100; H := (C - C div 4 - (8*C+13) div 25 + 19*G + 15) mod 30; I := H - (H div 28)*(1 - (H div 28)*(29 div (H + 1))*((21 - G) div 11)); J := (Year + Year div 4 + I + 2 - C + C div 4) mod 7; L := I - J; m := 3 + (L + 40) div 44; d := L + 28 - 31*(m div 4); y := Year; E := EncodeDate(y, m, d); while DayOfWeek(E) > 1 do E := E + 1; Result := E; end; { Utilizzo: var EasterDate: TDateTime; ... EasterDate := GetEaster(2002); }
Funzione di controllo utilizzo di un drive
20 ago 2007
La funzione controlla se il drive indicato come parametro è pronto per l’utilizzo
function IsDriveReady(DriveLetter : char) : bool;
var
OldErrorMode : Word;
OldDirectory : string;
begin
OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
GetDir(0, OldDirectory);
{$I-}
ChDir(DriveLetter + ':');
{$I+}
if IOResult <> 0 then
Result := False
else
Result := True;
ChDir(OldDirectory);
SetErrorMode(OldErrorMode);
end; { IsDriveReady }//Esempio di utilizzo:
if not IsDriveReady('A') then
ShowMessage('Drive Not Ready')
else
ShowMessage('Drive is Ready');
La funzione controlla se il drive indicato come parametro è pronto per l’utilizzo
function IsDriveReady(DriveLetter : char) : bool; var OldErrorMode : Word; OldDirectory : string; begin OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX); GetDir(0, OldDirectory); {$I-} ChDir(DriveLetter + ':'); {$I+} if IOResult <> 0 then Result := False else Result := True; ChDir(OldDirectory); SetErrorMode(OldErrorMode); end; { IsDriveReady }//Esempio di utilizzo: if not IsDriveReady('A') then ShowMessage('Drive Not Ready') else ShowMessage('Drive is Ready');
Rilevare la velocita della CPU
20 ago 2007
Funzione che permette di rilevare la velocita della CPU
function GetCPUSpeed: Double;
const
DelayTime = 500;
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end; { asm }
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end; { asm }
SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
end; { GetCPUSpeed }
Funzione che permette di rilevare la velocita della CPU
function GetCPUSpeed: Double; const DelayTime = 500; var TimerHi, TimerLo: DWORD; PriorityClass, Priority: Integer; begin PriorityClass := GetPriorityClass(GetCurrentProcess); Priority := GetThreadPriority(GetCurrentThread); SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL); Sleep(10); asm dw 310Fh // rdtsc mov TimerLo, eax mov TimerHi, edx end; { asm } Sleep(DelayTime); asm dw 310Fh // rdtsc sub eax, TimerLo sbb edx, TimerHi mov TimerLo, eax mov TimerHi, edx end; { asm } SetThreadPriority(GetCurrentThread, Priority); SetPriorityClass(GetCurrentProcess, PriorityClass); Result := TimerLo / (1000.0 * DelayTime); end; { GetCPUSpeed }
Nascondere la taskBar
20 ago 2007
procedure ShowTaskBar(bShow: Boolean);
begin
if bShow = True then
ShowWindow(FindWindow('Shell_TrayWnd',nil), SW_SHOWNA)
else ShowWindow(FindWindow('Shell_TrayWnd',nil), SW_HIDE);
end;
procedure ShowTaskBar(bShow: Boolean); begin if bShow = True then ShowWindow(FindWindow('Shell_TrayWnd',nil), SW_SHOWNA) else ShowWindow(FindWindow('Shell_TrayWnd',nil), SW_HIDE); end;














