Ver Mensaje Individual
  #9  
Antiguo 08-04-2004
Telemaco Telemaco is offline
Miembro
 
Registrado: feb 2004
Posts: 50
Reputación: 21
Telemaco Va por buen camino
Hola a todos de nuevo y disculparme pero no sabia que debia utilizar al etiqueta Code, aqui os paso de nuevo el codigo.

Código:
   var
     manyana,tarde:boolean;
     M1,M2,T1,T2:String;
      op,hor,min:integer;
   
      h1,h2:string;
      ht : array [0..2] of char;
      mt : array [0..5] of char;
      x:STRING;
   
      m,t:Tdatetime;
      horas:string;
      i:byte;
      hh,mm:string;
      hint,mint:integer;
   
   begin
    op:= strtoint(FCronos.TipoAccion.text);
    case op of
     1 : {Actualizo los campos autocalculados'}
           begin
             manyana:=false;
             tarde:=false;
              if Tfichajes.FieldByName('HoraEntM').AsString >'00:00:00'
                 then  begin
                         M1:=TFichajes.FieldbyName('HoraEntM').AsString;
                       end
                 else  begin
                        manyana:=true;
                        {    M1:='07:07:00';}
                       end;
              if (TFichajes.FieldByName('HoraSalM').AsString) > '00:00:00'
                 then  begin
                        M2:=Tfichajes.FieldByName('HoraSalM').Asstring;
                       end
                 else  begin
                        manyana:=true;
                       {  M2:='13:33:00'}
                       end;
              if TFichajes.FieldByName('HoraEntT').AsString > '00:00:00'
                 then begin
                       T1:=Tfichajes.fieldbyname('HoraEntT').AsString;
                       end
                 else  begin
                        Tarde:=true;
                         end;
              if TFichajes.FieldByName('HoraSalT').AsString > '00:00:00'
                 then  begin
                          T2:=Tfichajes.fieldbyname('HoraSalT').AsString;
                       end
                 else  begin
                        Tarde:=true;
                       end;
   
             if not manyana
                 then h1:=timetostr(strtotime(M1)-strtotime(M2))
                 else  begin
                        h1:='00:00:00';
                        manyana:=true;
                       end;
             if not tarde
                 then h2:=timetostr(strtotime(T1)-strtotime(T2))
                 else  begin
                         h2:='00:00:00';
                         tarde:=true;
                       end;
   
             x:=timetostr((strtotime(h1)+strtotime(h2)));
             if (not tarde) and (not manyana)
                 then  begin
                       FFichaEmp.GEFichaje.Font.color := clnavy;
   
   
                       TFichajes.FieldByName('HTXT').AsString:=x;
                       mm:='';hh:='';
                       TFichajes.fieldbyname('Mayana').asstring:=h1;
                       TFichajes.fieldbyname('Tarde').asstring:=h2;
   
                       horas:=x;
                       for i:=1 to length(horas) do
                         begin
                              if Horas[i] <> ':'
                                 then if i<3 then hh:=hh+Horas[i]
                                         else if i>3 then
                                     if i<6 then mm:=mm+Horas[i];
                         end;
                       hint:=strtoint(hh);
                       mint:=strtoint(mm);
                       TFichajes.Edit;   { AL AÑADIR ESTA LINEA ME DA DESBORDAMIENTO}
                       TFichajes.FieldByName('Horas').AsInteger:= hint;
                       TFichajes.FieldByName('Minutos').AsInteger:=mint;
   
                       end
                 else begin
                       FFichaEmp.GEFichaje.Font.Color :=clred;
                       TFichajes.FieldByName('HTXT').AsString:=x;
   
                       mm:='';hh:='';
                       horas:=x;
   
                       for i:=1 to length(horas) do
                         begin
                              if Horas[i] <> ':'
                                 then if i<3 then hh:=hh+Horas[i]
                                         else if i>3 then
                                     if i<6 then mm:=mm+Horas[i];
                         end;
                       hint:=strtoint(hh);
                       mint:=strtoint(mm);
                       TFichajes.Edit;
                       TFichajes.FieldByName('Horas').AsInteger:= hint;
                       TFichajes.FieldByName('Minutos').AsInteger:=mint;
   
                      end;
He probado tambien a utilizar el OnChange pero no termina de funcionarme bien, ya que no actua en todos los casos, sabriais decirme por que ocurre esto? os adjunto el codigo

Código:
 procedure TDM1.TFichajesHoraSalMChange(Sender: TField);
 var
 
    manyana,tarde:boolean;
    M1,M2,T1,T2:String;
    op,hor,min:integer;
 
    h1,h2:string;
    ht : array [0..2] of char;
    mt : array [0..5] of char;
    x:STRING;
 
    m,t:Tdatetime;
    horas:string;
    i:byte;
    hh,mm:string;
    hint,mint:integer;
 
 begin
    manyana:=false;
 
    if dm1.Tfichajes.FieldByName('HoraEntM').AsString >'00:00:00'
 	 then M1:=dm1.TFichajes.FieldbyName('HoraEntM').AsString
 	 else  manyana:=true;
    if (dm1.TFichajes.FieldByName('HoraSalM').AsString) > '00:00:00'
 	 then M2:=dm1.Tfichajes.FieldByName('HoraSalM').Asstring
 	 else manyana:=true;
    if not manyana
 		then h1:=timetostr(strtotime(M1)-strtotime(M2))
 		else  begin
 			   h1:='00:00:00';
 			   manyana:=true;
 			 end;
 	  x:=timetostr(strtotime(h1));
 	  if (not manyana)
 		  then  begin
 			   mm:='';hh:='';
 			   DM1.TFichajes.Edit;
 			   DM1.TFichajes.fieldbyname('Mayana').asstring:=h1;
 			   horas:=x;
 			   for i:=1 to length(horas) do
 				begin
 				   if Horas[i] <> ':'
 					  then if i<3
 						 then hh:=hh+Horas[i]
 						 else if i>3 then
 				   if i<6 then mm:=mm+Horas[i];
 				end;
 			   hint:=strtoint(hh);
 			   mint:=strtoint(mm);
 
 			   dm1.TFichajes.FieldByName('Horas').AsInteger:= hint;
 			   dm1.TFichajes.FieldByName('Minutos').AsInteger:=mint;
 			   end;
 
    dm1.TFichajes.Post;
    dm1.TFichajes.next;
 
 end;
Se dispara el evento en el momento que actualizo o modifico un valor del field HSalM. Al escribir este evento he eliminado el codigo que asiganba valores en el evento OnCalcFields, pero ahora tambien me aparece el "Stack Overflow" , alguna sugerencia???

Gracias a todos.
Responder Con Cita