Ver Mensaje Individual
  #15  
Antiguo 17-11-2016
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Reputación: 20
movorack Va camino a la famamovorack Va camino a la fama
Si!. No es un archivo binario. Es solo texto.

Hice el ejercicio y pude pasarlo del archivo a un ClientDataSet pero tuve problemas para cargar todas las líneas.

Básicamente cargué el archivo en un StringList, luego a la línea que carga le voy dando manejo con los posibles tamaños de campos y eso lo voy subiendo al dataset.

Código Delphi [-]
procedure TForm1.SpeedButton1Click(Sender: TObject);
  const
    C_LENREG = 205;
  var
    lStFile : TFileName;
    lSlFile : TStrings;
    lStLineas : TStrings;
    lLinea : String;
begin
  Memo1.Lines.Clear;
  CdsTemp.EmptyDataSet;

  lStFile := StringReplace(ParamStr(0), '.exe', '.fil', [rfIgnoreCase, rfReplaceAll]);
  if not FileExists(lStFile) then
    Exit;

  TSpeedButton(Sender).Down := True;
  FLeer := True;

  lSlFile := TStringList.Create;
  lStLineas := TStringList.Create;
  try
    lSlFile.LoadFromFile(lStFile);
    lSlFile[0] := StringReplace(lSlFile[0], #0, ' ', [rfIgnoreCase, rfReplaceAll]);
    while (Length(lSlFile[0]) > 1) and FLeer do
    begin
      lLinea := Copy(lSlFile[0], 1, C_LENREG);
      lStLineas.Add(lLinea);
      Memo1.Lines.Add(lLinea);

      if CdsTemp.State in [dsEdit, dsInsert] then
        CdsTemp.Cancel;

      CdsTemp.Append;
      CdsTempField01.AsString := Copy(lLinea, 001, 06);
      CdsTempField02.AsString := Copy(lLinea, 007, 58);
      CdsTempField03.AsString := Copy(lLinea, 065, 25);
      CdsTempField04.AsString := Copy(lLinea, 090, 50);
      CdsTempField05.AsString := Copy(lLinea, 140, 18);
      CdsTempField06.AsString := Copy(lLinea, 158, 11);
      CdsTempField07.AsString := Copy(lLinea, 169, 10);
      CdsTempField08.AsString := Copy(lLinea, 179, 06);
      CdsTempField09.AsString := Copy(lLinea, 185, 20);
      CdsTempField10.AsString := Copy(lLinea, 205, 01);
      CdsTemp.Post;

      lSlFile[0] := Copy(lSlFile[0], Length(lLinea) + 1, Length(lSlFile[0]));

      Application.ProcessMessages;
      Sleep(250);
    end;
  finally
    FreeAndNil(lStLineas);
    FreeAndNil(lSlFile);
  end;
end;

Adjunto el fuente del ejercicio. Para usarlo debes modificar el nombre del archivo ".fil" a Project1.fil y colocarlo en el directorio del ejecutable. "Project1.fil"
__________________
Buena caza y buen remar... http://mivaler.blogspot.com

Última edición por movorack fecha: 24-07-2017 a las 16:52:39.
Responder Con Cita