Sep 14
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 a leggere »
Aug 20
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);
}
Aug 20
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');
Aug 20
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 }