sábado, 7 de novembro de 2009

Mostrando a Data a Hora e o nome da Maquina em um StatusBar



Insira um statusbar e um timer no formulario


Dê dois cliques no status bar e configure os panels


De dois cliques no timer e digite.....

StatusBar.Panels[3].Text := mostrahora();

StatusBar.Panels[1].Text := mostradata();

StatusBar.Panels[2].Text := 'Máquina ' + NomeDoComputador();


Colocar os nomes das funçoes abaixo de

public
{ Public declarations }
end;
function MyData(Data: TDate): String;
function mostradata: string;
function mostrahora: string;
function NomeDoComputador (): string;



funçoes estas que deverao estar abaixo do implementation do formulario

implementation

function mostrahora: string;
begin
mostrahora := timetostr(time);
end;


// funçao mostrar a data

function mostradata: string;
var
dthoje: TDatetime;
diasemana: integer;
strdiasemana: string;
begin
dthoje := date;
diasemana := dayofweek(dthoje);
case diasemana of
1: strdiasemana := 'Domingo';
2: strdiasemana := 'Segunda-feira';
3: strdiasemana := 'Terça-feira';
4: strdiasemana := 'Quarta-feira';
5: strdiasemana := 'Quinta-feira';
6: strdiasemana := 'Sexta-feira';
7: strdiasemana := 'Sábado';
end;
mostradata := strdiasemana+' '+datetostr(dthoje);
end;

// Retorna o nome do computador.

function NomeDoComputador (): string;const
MAX_COMPUTER_LENGTH = 30;
var
pNome : PChar;
len : DWord;beginResult := '';
trylen := MAX_COMPUTER_LENGTH + 1;
GetMem(pNome,len);
if GetComputerName(pNome, len) then
begin
Result := pNomeend else beginResult := 'NÃo foi possivel obter o nome deste computador!';
end;
inallyFreeMem(pNome, len);
end;
end;

Nenhum comentário:

Postar um comentário