terça-feira, 24 de abril de 2012

Como incrementar a Barra de Status

No formulário principal coloque uma statusbar com 3 panels,1 time e aplicationeventos e digite as funções abaixo ->

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

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;

// Selecione o aplicationeventos e na guia eventos do objeto inspector depois clique no evento OnHint e digite o código ->

procedure TFnomedoform.ApplicationEvents1Hint(Sender: TObject);
Begin
StatusBar1.Panels[2].Text:=Application.Hint;
// todos os hints do seu projeto apareceram no statusbar
end;

// agora faça com que suas funções apareçam o resultado

procedure TFnomedoform.Timer1Timer(Sender: TObject);
var
    presente:tdatetime;
    ano,mes,dia:word;
begin
   presente:=now;
   decodedate(presente,ano,mes,dia);
   case mes of
     1:STATUSBAR1.PANELS[1].TEXT:=' JANEIRO '+inttostr(ano);
     2:STATUSBAR1.PANELS[1].TEXT:='FEVEREIRO'+inttostr(ano);
     3:STATUSBAR1.PANELS[1].TEXT:='MARÇO '+inttostr(ano);
     4:STATUSBAR1.PANELS[1].TEXT:='ABRIL '+inttostr(ano);
     5:STATUSBAR1.PANELS[1].TEXT:='MAIO '+inttostr(ano);
     6:STATUSBAR1.PANELS[1].TEXT:='JUNHO '+inttostr(ano);
     7:STATUSBAR1.PANELS[1].TEXT:='JULHO '+inttostr(ano);
     8:STATUSBAR1.PANELS[1].TEXT:='AGOSTO '+inttostr(ano);
     9:STATUSBAR1.PANELS[1].TEXT:='SETEMBRO '+inttostr(ano);
     10:STATUSBAR1.PANELS[1].TEXT:='OUTUBRO '+inttostr(ano);
     11:STATUSBAR1.PANELS[1].TEXT:='NOVEMBRO '+inttostr(ano);
     12:STATUSBAR1.PANELS[1].TEXT:='DEZEMBRO '+inttostr(ano);
   end;
STATUSBAR1.PANELS[0].TEXT:=mostrahora();
STATUSBAR1.PANELS[1].TEXT:=mostradata();
end;

// ***** Viu como é fácil enfeitar seu projeto ******

Obter a célula de um StringGrid que está sob o cursor do mouse

Inclua na seção uses: Windows

procedure MouseCell(Grid: TStringGrid;
var Coluna, Linha: integer);
var
Pt: TPoint;
begin
GetCursorPos(Pt);
Pt := Grid.ScreenToClient(Pt);
if PtInRect(Grid.ClientRect, Pt) then
Grid.MouseToCell(Pt.X, Pt.Y, Coluna, Linha)
else begin
Coluna := -1;
Linha := -1;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Coluna, Linha: integer;
begin
MouseCell(StringGrid1, Coluna, Linha);
if (Coluna >= 0) and (Linha >= 0) then
Caption := 'Coluna: ' + IntToStr(Coluna) + ' - ' +
'Linha: ' + IntToStr(Linha);
else
Caption := 'O mouse não está no StringGrid';
end;