Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 04-02-2019
DarthGomis DarthGomis is offline
Registrado
 
Registrado: feb 2019
Posts: 5
Poder: 0
DarthGomis Va por buen camino
Lectura de fichero errónea

Hola,

Estoy desarrollando una app que lea un fichero con la forma:

N:Nombre;D:0000;F:00/00/0000

Donde N: es un string, D: es un entero y F: es una fecha. (cabe destacar que el orden puede estar alterado y puede que alguna linea no esté bien escrita)

El problema reside en que el método en el cual almaceno los contenidos de la línea en una lista, al llegar al segundo ';' se revoluciona y hace cosas extrañas.

Código Delphi [-]
procedure TForm1.CreateList(fileName: string);
var
  tempLine: string;      //Line with all data
  line: TLine;           //Line with data fragmented
  cha: char;
  Data: TextFile;
  tipe: string;          //Tipe of data
  temp: string;          //temporally data to storage
  nameData: string;          //name data
  numberData: integer;       //number data
  dateData: TDateTime;
  lineData: integer;       //date data

begin
  fileList := TList.Create;
  wrongLines := 0;
  rightLines := 0;
  lineData := 1;

  AssignFile(Data, fileName);
  Reset(Data);

  while not Eof(Data) do
  begin
    while not Eoln(Data) do
    begin
      Read(Data, cha);
      //Select tipe of data
      if UpperCase(temp) = 'N:'
      then
      begin
        tipe := temp;
        temp := '';
      end
      else if UpperCase(temp) = 'D:'
      then
      begin
        tipe := temp;
        temp := '';
      end
      else if UpperCase(temp) = 'F:'
      then
      begin
        tipe := temp;
        temp := '';
      end;
      if (cha = ';') or (lineData = 3)
      then
      begin
        //ShowMessage(tipe);
        if tipe = 'N:'
        then
        begin
          try
            nameData := temp;
            temp:='';
          except
            Inc(wrongLines);
            temp:='';
            break;
          end;
        end
        else if tipe = 'D:'
        then
        begin
          try
            numberData := StrToInt(temp);
            temp:='';
          except
            Inc(wrongLines);
            temp:='';
            break;
          end;
        end
        else if tipe = 'F:'
        then
        begin
          try
            //ShowMessage(temp);
            dateData := StrToDate(temp);
            temp:='';
          except
            //ShowMessage('puto');
            Inc(wrongLines);
            temp:='';
            break;
          end;
        end
        else
        ShowMessage(IntToStr(lineData));
        Inc(lineData);
      end
      else temp := temp + cha;
      ShowMessage('Tipo: ' + tipe + #13 + 'Temp: ' + temp + #13 + 'Caracter: ' + cha
                  + #13 + 'N: ' + nameData + #13 + 'D: ' + IntToStr(numberData) + #13 +
                  'F: ' + DateToStr(dateData));
    end;
    if  not (nameData = '')
    then
    begin
      if not (numberData = 0)
      then
      begin
        if not (dateData = 0)
        then
        begin
          //ShowMessage(DateToStr(dateData));
          line := TLine.Create(nameData, numberData, dateData);
          Inc(rightLines);
          fileList.Add(line);
        end;
      end;
    end;
    nameData := '';
    numberData := 0;
    dateData := 0;
    temp := '';
    lineData := 1;
    ReadLn(Data,tempLine);
  end;
CloseFile(Data);

end;

TList es una clase creada para que me diferencie qué es cada cosa

Código Delphi [-]
TLine = class

  //Data fields of a line
  private
    n: string;      //N:
    d: integer;     //D:
    f: TDateTime;   //F:

  //Properties to read the data values
  public

    line : string;

    property NewName: string
      read n;
    property NewNumber: integer
      read d;
    property NewDate: TDateTime
      read f;

  //Constructor
  constructor  Create(const n : string;
                      const d : integer;
                      const f : TDateTime);
  end;

Sería de gran ayuda que me orientaseis un poco porque soy nuevo en delphi y no tengo mucha idea.
Responder Con Cita
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Lectura errónea de la versión de mi aplicación Manuel Varios 3 22-09-2011 15:31:38
Llamada erronea Alexandro Humor 1 16-04-2009 20:42:37
Cómo saber si un fichero esta marcado de sólo lectura ? David Varios 2 13-08-2008 17:20:19
Lectura fichero escribe a registro Guillermo80 Varios 3 23-02-2008 23:56:03
Lectura de fichero clipper Isabel_AS Varios 8 10-04-2007 15:39:32


La franja horaria es GMT +2. Ahora son las 16:41:59.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi