Ver Mensaje Individual
  #6  
Antiguo 02-12-2005
Avatar de turekon
turekon turekon is offline
Registrado
 
Registrado: nov 2005
Posts: 5
Reputación: 0
turekon Va por buen camino
hola puedes utilizar esta funcion que permite ajustar el tamaño de la cadena que se pasa por parametro, llenando los espacios con el caracter requerido, así como ajustar la alineacion de la cadena.

Código Delphi [-]
function FormatString(Cad, Str :String; Largo, Justi :Integer):String;
    var
       StrCad : String;
       CadO   : String;
       i,Tam  : Integer;
    begin
       StrCad := Cad;
       if StrCad = '' then
       begin
         StrCad := ' ';
       end;
       CadO := StrCad;
       if Largo > Length(StrCad) then
       begin
          Case Justi of
              1 : begin
                   for i := 1 to (Largo - Length(CadO)) do
                   begin
                       StrCad := StrCad + Str;
                   end;
                 end;
             2 : begin
                   for i := 1 to (Largo - Length(CadO)) do
                   begin
                       StrCad := Str + StrCad;
                   end;
                 end;
             3 : begin
                   Tam := (Largo - Length(CadO)) div 2;
                   for i := 1 to Tam do
                   begin
                    StrCad := Str + StrCad + Str;
                   end;
                   if (Largo-Length(CadO) mod 2 <> 0) then
                   begin
                       StrCad := StrCad;
                   end;
                 end;
          end;
        end
          else
           if Largo < Length(StrCad) then
          begin
              StrCad:=Copy(StrCad,1,Largo);
          end;
        FormatString:=StrCad;
    end;

espero sirva, para mis reportes y logs de seguimiento ha sido muy util.

asi lo utilizo:

Código Delphi [-]
         Writeln(ReporteF, FormatString( 'Nombre Archivo', ' ', 35, 1) +
                                  FormatString( 'Tamaño_Archivo', ' ', 20, 1) +
                            FormatString( 'Fecha', ' ', 20, 1) +
                            FormatString( 'Hora', ' ', 20, 1) +
                            FormatString( 'Estado Archivo', ' ', 15, 1));
          Writeln(ReporteF, FormatString( '-', '-', 35, 1) +
                                  FormatString( '-', '-', 20, 1) +
                            FormatString( '-', '-', 20, 1) +
                            FormatString( '-', '-', 20, 1) +
                            FormatString( '-', '-', 15, 1));
 
          for Ind:=0 to FileBox.Items.Count-1 do
          begin
             Writeln(ReporteF, FormatString( FileBox.Items.Strings[Ind], ' ', 35, 1) +
                                     FormatString( IntToStr(Tamanyo(FileBox.Items.Strings[Ind])), ' ', 20, 1) +
                               FormatString( FormatDateTime('yyyy-mm-dd', Now), ' ', 20, 1) +
                               FormatString( FormatDateTime('hh:mm:ss', Now), ' ', 20, 1) +
                               FormatString( 'Procesado', ' ', 15, 1));
          end;

un ejemplo de como quedaria el reporte.

Código Delphi [-]
  Nombre Archivo                     Tamaño_Archivo      Fecha               Hora                Estado Archivo 
  --------------------------------------------------------------------------------------------------------------
  00000123452005112815-34-29.LIS     293408              2005-12-01          15:06:29            Procesado

Última edición por turekon fecha: 02-12-2005 a las 15:17:21.
Responder Con Cita