Read 1 character from ascii file

ajhvdbajhvdb Member Posts: 672
edited 2008-09-09 in Navision Attain
GtLine = Text = Size 1

1.
If I use:
File.Read(GtLine)

and the ascii line is longer then 1 position NAV generates an error.

How to read only 1 character at a time?

2.
I can do it with an instream:
Instream.Read(GtLine, 1)

But now I can't use the .seek function... (I need this too :? )

3.
Below does work, after a seek:
File.SEEK(2);
File.CREATEINSTREAM(Instream);
Instream.Read(GtLine, 1)

But I don't know if this will create new problems if it is called 20000 times?

Answers

  • kinekine Member Posts: 12,562
    If you set the file into binary mode (textmode := false) and you create one variable of type Char, you just can read one byte with File.Read(myCharVar). That's all... no problem with reading whole file in this way (good for reading file with longer lines than 1000 chars...).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ajhvdbajhvdb Member Posts: 672
    I've changed the var Text1 to a var Char and no errors. Thx. Now I can read those long lines...
  • ajhvdbajhvdb Member Posts: 672
    Update:

    Normally while reading textfiles I would use the function ansi2ascii

    but if I do this with the type Char characters are converted???

    Here is my code:
    vPfImport.SEEK(vPiLinePosBeg);
    LtInput := '';
    LiPos := 0;
    LiX := 0;
    WHILE (vPfImport.POS <= vPiLinePosEnd) AND 
          (vPfImport.POS < vPfImport.LEN) DO BEGIN
      vPfImport.READ(LcChar);
      LiFilePos := vPfImport.POS;
      LtChar := FORMAT(LcChar);
      LiPos += 1;
      IF (LiPos >= LiFrom) AND (LiPos <= LiTo) THEN BEGIN
        LiX += 1;
        IF (LiX <= 1024) THEN BEGIN
          LtInput[LiX] := LtChar[1];
        END;
      END;
    END;
    ---->>  LtInput := Ansi2Ascii(LtInput, FALSE);
    

    Without this line everything is ok, is this correct?
  • ajhvdbajhvdb Member Posts: 672
    :-k Has not one of you experienced this?
Sign In or Register to comment.