Really easy question about FileStream

Hi to everyone,
I've got a problem with TFileStream.
How can I create a new line??

For example, if I'd have to write in a filestream this sentence formatted just like this:

Hi
I am
Sergio

How can i add newlines???

Sorry for my english and thank, Bye.


Comments

  • : Hi to everyone,
    : I've got a problem with TFileStream.
    : How can I create a new line??
    :
    : For example, if I'd have to write in a filestream this sentence formatted just like this:
    :
    : Hi
    : I am
    : Sergio
    :
    : How can i add newlines???
    :
    : Sorry for my english and thank, Bye.
    :
    :
    :
    New lines can be created by writing the line ending code: #13#10.
  • : Hi to everyone,
    : I've got a problem with TFileStream.
    : How can I create a new line??
    :
    : For example, if I'd have to write in a filestream this sentence formatted just like this:
    :
    : Hi
    : I am
    : Sergio
    :
    : How can i add newlines???
    :
    : Sorry for my english and thank, Bye.
    :
    :
    :
    I suggest you to use the simple AssignFile, Read, Write, CloseFile, Rewrite, Reset procedures. They are much easy to handle. TFileStream is a bit expert.
    Here's an example:
    [code]
    var
    stream:text;

    procedure writesergio;
    begin
    AssignFile(stream,'Sergio.txt');
    Rewrite(stream); // open the file for writing
    writeln(stream,'Hi');
    writeln(stream,'I am');
    writeln(stream,'Sergio');
    closefile(stream);
    end;
    [/code]

    For reading:
    [code]
    var
    stream:text;

    procedure writesergio;
    var
    s,t,u:string;
    begin
    AssignFile(stream,'Sergio.txt');
    Reset(stream); // open the file for reading
    readln(stream,s);
    readln(stream,t);
    readln(stream,u);
    closefile(stream);
    end;
    [/code]

    I suggest these, but if you really need TFileStream:
    [code]
    // lets say projectfile is a TFileStream
    projectfile:=tfilestream.create('sergio.txt',fmcreate);
    projectfile.write('Hi',strlen('Hi'));
    projectfile.write('I am',strlen('I am'));
    projectfile.write('Sergio',strlen('Sergio'));
    projectfile.free;
    [/code]
    Hope this help you out.

    ****************
    Any questions? Just ask!

    :-) [b][blue]GAASHIUS[/blue][/b] :-)


  • : : Hi to everyone,
    : : I've got a problem with TFileStream.
    : : How can I create a new line??
    : :
    : : For example, if I'd have to write in a filestream this sentence formatted just like this:
    : :
    : : Hi
    : : I am
    : : Sergio
    : :
    : : How can i add newlines???
    : :
    : : Sorry for my english and thank, Bye.
    : :
    : :
    : :
    : I suggest you to use the simple AssignFile, Read, Write, CloseFile, Rewrite, Reset procedures. They are much easy to handle. TFileStream is a bit expert.
    : Here's an example:
    : [code]
    : var
    : stream:text;
    :
    : procedure writesergio;
    : begin
    : AssignFile(stream,'Sergio.txt');
    : Rewrite(stream); // open the file for writing
    : writeln(stream,'Hi');
    : writeln(stream,'I am');
    : writeln(stream,'Sergio');
    : closefile(stream);
    : end;
    : [/code]
    :
    : For reading:
    : [code]
    : var
    : stream:text;
    :
    : procedure writesergio;
    : var
    : s,t,u:string;
    : begin
    : AssignFile(stream,'Sergio.txt');
    : Reset(stream); // open the file for reading
    : readln(stream,s);
    : readln(stream,t);
    : readln(stream,u);
    : closefile(stream);
    : end;
    : [/code]
    :
    : I suggest these, but if you really need TFileStream:
    : [code]
    : // lets say projectfile is a TFileStream
    : projectfile:=tfilestream.create('sergio.txt',fmcreate);
    : projectfile.write('Hi',strlen('Hi'));
    : projectfile.write('I am',strlen('I am'));
    : projectfile.write('Sergio',strlen('Sergio'));
    : projectfile.free;
    : [/code]
    : Hope this help you out.
    :
    : ****************
    : Any questions? Just ask!
    :
    : :-) [b][blue]GAASHIUS[/blue][/b] :-)
    :
    :
    :
    Sorry, I maybe was writing when Zibadian posted that. I thought you need to create lines - sorry for my terrible english.

    ****************
    Any questions? Just ask!

    :-) [b][blue]GAASHIUS[/blue][/b] :-)


  • : : Hi to everyone,
    : : I've got a problem with TFileStream.
    : : How can I create a new line??
    : :
    : : For example, if I'd have to write in a filestream this sentence formatted just like this:
    : :
    : : Hi
    : : I am
    : : Sergio
    : :
    : : How can i add newlines???
    : :
    : : Sorry for my english and thank, Bye.
    : :
    : :
    : :
    : I suggest you to use the simple AssignFile, Read, Write, CloseFile, Rewrite, Reset procedures. They are much easy to handle. TFileStream is a bit expert.
    : Here's an example:
    : [code]
    : var
    : stream:text;
    :
    : procedure writesergio;
    : begin
    : AssignFile(stream,'Sergio.txt');
    : Rewrite(stream); // open the file for writing
    : writeln(stream,'Hi');
    : writeln(stream,'I am');
    : writeln(stream,'Sergio');
    : closefile(stream);
    : end;
    : [/code]
    :
    : For reading:
    : [code]
    : var
    : stream:text;
    :
    : procedure writesergio;
    : var
    : s,t,u:string;
    : begin
    : AssignFile(stream,'Sergio.txt');
    : Reset(stream); // open the file for reading
    : readln(stream,s);
    : readln(stream,t);
    : readln(stream,u);
    : closefile(stream);
    : end;
    : [/code]
    :
    : I suggest these, but if you really need TFileStream:
    : [code]
    : // lets say projectfile is a TFileStream
    : projectfile:=tfilestream.create('sergio.txt',fmcreate);
    : projectfile.write('Hi',strlen('Hi'));
    : projectfile.write('I am',strlen('I am'));
    : projectfile.write('Sergio',strlen('Sergio'));
    : projectfile.free;
    : [/code]
    : Hope this help you out.
    :
    : ****************
    : Any questions? Just ask!
    :
    : :-) [b][blue]GAASHIUS[/blue][/b] :-)
    :
    :
    :
    In some cases a TStream descendant is better than using a file type variable. For example: if you want to expand the code to include an internet communication, you can easily use a TSocketStream instead of a TFileStream and your code doesn't need to be changed. In addition the TStream can also natively read/write TComponents, which makes it easier to create component resources.
    So using a TStream is somewhat more complex than a file type variable, but much more flexible.
  • Thanks to yours suggestions I've menaged to solve my problem using TFileStream and #13#10 constant.
    It's not really intuitive for being a name of the new line charachter!!! :D
  • : Thanks to yours suggestions I've menaged to solve my problem using TFileStream and #13#10 constant.
    : It's not really intuitive for being a name of the new line charachter!!! :D
    :
    #13 is the ASCII code for enter, and #10 is the ASCII code for line-feed. This is very intuitive, if you know the ASCII codes. Otherwise, you are correct. If you want to you can also use this:
    [code]
    const
    sLineFeed = #13#10;
    [/code]
    Now, if you want to insert a line-feed, you can simply use the named constant instead of the ASCII codes.
  • Thank you very much!!
    Ahhhh.... now I understand, nice!!
    I wish you a nice week end!

    Thank you again.

    Sergio
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories