Editar

Share via


InStream.ReadText(var Text [, Integer]) Method

Version: Available or changed with runtime version 1.0.

Reads text from an InStream object.

Syntax

[Read := ]  InStream.ReadText(var Variable: Text [, Length: Integer])

Parameters

InStream
 Type: InStream
An instance of the InStream data type.

Variable
 Type: Text
The variable that receives the characters that were read.

[Optional] Length
 Type: Integer
The number of characters to be read. If you do not specify this parameter, the maximum length of the string is used.

Return Value

[Optional] Read
 Type: Integer
The number of characters that were read. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

ReadText reads the stream until the specified number of bytes, the maximum length of the string, a zero byte, or until the end of the line. For more information about how zero bytes and line endings are read, see Write, WriteText, Read, and ReadText Method Behavior Regarding Line Endings and Zero Terminators.

Data is read in text format.

If you do not use the optional return value and the data being read is less than the length requested to be read, an error message is displayed.

If you use the return value, you must verify the validity of the data that has been read.

Example

This example shows to use the InStream.ReadText method to read stream from a text file. This example is only supported on Business Central on-premises.

 var
    FileTest: File;
    StreamInTest: Instream;
    Txt: Text;
    Int: Integer;
begin
    FileTest.Open('c:\XMLDocs\NewTest.txt');  
    FileTest.CreateInStream(StreamInTest);  
    // Starting a loop  
    while not (StreamInTest.EOS) do begin 
      Int := StreamInTest.ReadText(Txt,100);  
      Message(Txt + '\Size: ' + Format(Int));  
    end;  
    FileTest.Close();  
end;

See Also

InStream Data Type
Get Started with AL
Developing Extensions