Para isso vamos precisar declarar uma function na seção private da classe do nosso formulário.
Listagem 1: Declaração da function
type
TForm1 = class(TForm)
private
{ Private declarations }
function LigadoEm: string;
public
{ Public declarations }
end;
Listagem 2: Implementação da function LigadoEm
function TForm1.LigadoEm: string;
const
Ticks_Dia: Integer = 1000 * 60 * 60 * 24;
Ticks_Hora: Integer = 1000 * 60 * 60;
Ticks_Numero: Integer = 1000 * 60;
Ticks_Segundo: Integer = 1000;
var
t: Longword;
d, h, m, s: Integer;
begin
t := GetTickCount;
d := t div Ticks_Dia;
Dec(t, d * Ticks_Dia);
h := t div Ticks_Hora;
Dec(t, h * Ticks_Hora);
m := t div Ticks_Numero;
Dec(t, m * Ticks_Numero);
s := t div Ticks_Segundo;
Result := 'Ligado em : ' + IntToStr(d) + ' Dias ' + IntToStr(h) + ' Horas ' + IntToStr(m) +
' Minutos ' + IntToStr(s) + ' Segundos';
end;
Listagem 3: Usando a function LigadoEm
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption := LigadoEm;
end;
Um abraço
Wesley Y