Ver Mensaje Individual
  #2  
Antiguo 03-04-2007
Avatar de ArdiIIa
[ArdiIIa] ArdiIIa is offline
Miembro Premium
 
Registrado: nov 2003
Ubicación: Valencia city
Posts: 1.481
Reputación: 22
ArdiIIa Va por buen camino
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
Const
Separador = ' '; //Este es el caracter que utilizamos de separador;
Var
Fichero : TStrings;
Sig : Integer;
Pos : Integer;
Copy_Ini : Integer;
Copy_Fin : Integer;
Longitud : Integer;
cTemp : String;
I, J, K : Integer;
////////////////////
Function pos_str(Cad : String; Car: Char; Ini : Integer) : Integer;
var
Cnt :Integer;
Longitud :Integer;
begin
Result := 0;
Longitud := Length(cad);
Cnt := Ini;
repeat
    Inc(Cnt);
    //Controlamos el separador y saltos de línea
    if (Cad[Cnt]=Car) or (Cad[Cnt]=#10) or (Cad[Cnt]=#13) then
    begin
        Result := Cnt -Ini;
        break;
    end;
until (Cnt > longitud) ;
end;
///////////////////////
begin
Fichero := TStringList.Create;
Fichero.LoadFromFile('Unit1.pas');  // Fichero a procesar
Longitud:=Length(Fichero.Text);
cTemp := Fichero.Text;
Fichero.Clear;
Pos:=0;

repeat
    Sig := Pos_Str(cTemp,Separador,Pos);
    if (sig=0) then break;
    Inc(pos,sig);
    copy_ini:=(pos-sig)+1;
    copy_fin:=sig-1;
    Fichero.Add(Trim(copy(cTemp,copy_ini,copy_fin)) );
until (sig=0);
//Acomodamos el StringGrid a la longitud del fichero, dependiendo del número de columnas.
StringGrid1.RowCount := (Fichero.Count -1) div StringGrid1.ColCount -1;
//Efectuamos el relleno del StringGrid

  K := 0;
  with StringGrid1 do
    for I := 0 to ColCount - 1 do
      for J:= 0 to RowCount - 1 do
        begin
          Cells[I,J] := Fichero[K]; 
          inc(K);
        end;

Fichero.Free;
end;

Creo que el procedimiento se explica por sí solo.
Espero que te sea de utilidad.

Saludos.
__________________
Un poco de tu generosidad puede salvar la vida a un niño. ASÍ DE SENCILLO
Responder Con Cita