Does anybody know why if I call the following function as f_txtRead5Chars(‘C:\Test.txt’); I get the following error “The text ‘ABCDEF’ in READ parameter no. 1 is too long.” ? PROCEDURE f_txtRead5Chars@21(p_txtFileName@1000000001 : Text) r_txtRead5Chars : Text; VAR l_fileCAB@1000000000 : File; BEGIN l_fileCAB.TEXTMODE(FALSE); l_fileCAB.OPEN(p_txtFileName); l_fileCAB.READ(r_txtRead5Chars); l_fileCAB.CLOSE; END; FILE C:\Test.txt ABCDEFGHIJKLMNOPQRSTUVWXYZ It is supposed that when TEXTMODE = FALSE, READ will determines the number of bytes to read based on the size of the variable (5) but the error message shows 6 chars. Thanks in advance, Jesús Soage
Originally posted by JSoage
It is supposed that when TEXTMODE = FALSE, READ will determines the number of bytes to read based on the size of the variable (5) but the error message shows 6 chars.
Hi Jesus, When you set the TEXTMODE to false, it means that you want to work with a binary file. In binary mode, the READ function will read the number of bytes or your variable (ex: 4 for an integer, 1 for a char, etc.), but it will not work if you use Complex variables like the type ‘Text’, because this type does not have a fixed length (i.e. fixed number of bytes). So, you have two options: #1 TEXTMODE = TRUE and READ to a tmpString variable (max 1024 char) With TEXTMODE = TRUE, READ reads the entire line of a text file. You will then have to extract the data from this variable #2 TEXTMODE = FALSE and READ your file char by char See the example below:
myFile.TEXTMODE(FALSE); myFile.OPEN('C:\temp\patate.txt'); FOR i := 1 TO 5 DO BEGIN myFile.READ(mychar); myString5chars[i] := mychar; //myString5chars := myString5chars + FORMAT(mychar); END; MESSAGE(myString5chars); myFile.CLOSE;