1 (edited by megood70 2016-02-10 18:04:51)

Topic: any one help me for this code

i need help check this code when the DateTime now is = date end....... .Then change color Cells[4,i] to Red.





procedure Form1_GridEmployees_OnChange (Sender: string);
var
   i: integer;
   c: integer;
begin
   
     c := Form1.GridEmployees.RowCount - 1;   for
     i := 0 to c do

     begin

                 If Form1.GridEmployees.Cells[4,i] = FormatDateTime('c', Now);
        Then Form1.GridEmployees.Cell[4,i].Color := clRed
       Else Form1.GridEmployees.Cell[4,i].Color := clLime;


     end;
     
end;

Post's attachments

Attachment icon chnage color.png 47.7 kb, 252 downloads since 2016-02-10 

Re: any one help me for this code

Hi Megood70,

I'd probably do it this way (although I'm sure there are other ways too).

procedure Form1_GridEmployees_OnChange (Sender: string);
var
   i,c: integer;
begin
  c := Form1.GridEmployees.RowCount - 1;
  for i := 0 to c do
  begin
    If Form1.GridEmployees.Cells[4,i] <= datetimetostr(now) then form1.GridEmployees.Cell[4,i].Color := clRed;
    If Form1.GridEmployees.Cells[4,i] >   datetimetostr(now) then form1.GridEmployees.Cell[4,i].Color := cllime;
  end;
end;

Hope this helps,
Derek

Re: any one help me for this code

Thank you very mutch Mr.Derek.....yes exactly ...