?
Solved

TFileStream

Posted on 2002-06-18
6
Medium Priority
?
1,047 Views
Last Modified: 2010-05-18
HiCan i read with TFileStream  line by line
(every Line can be in different length)

Example will be wellcome
thank u
Asi
0
Comment
Question by:asi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7088977
The easiest way to read a text file is to use a TStringList.

var
  List: TStringList;
begin
  List := TStringList.Create;
  List.LoadFromFile(FileName);
  // do something with the lsit
  List.Free;
end;
0
 

Author Comment

by:asi
ID: 7089401
I need to read a very  big file name.
TStringList is not the way
0
 
LVL 6

Expert Comment

by:edey
ID: 7090054
to do it with a stream you have to read the file char by char until you hit a #10. It's also possible to use a text file. my help (D6) contained this example:

AssignFile, OpenDialog, Readln, CloseFile Example:
var

  F: TextFile;
  S: string;
begin
  if OpenDialog1.Execute then            { Display Open dialog box }
  begin
    AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
    Reset(F);
    Readln(F, S);                        { Read first line of file }
    Edit1.Text := S;                     { Put string in a TEdit control }
    CloseFile(F);
  end;
end;

GL
Mike
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7091548
open using FileStream, then load stream data as needed, into TStringStream?
0
 

Accepted Solution

by:
philcm earned 75 total points
ID: 7108132
You'll need to create a command for your filestream!  Ideal thing is to creat a new Object that inherits TFileStream and add the funtion ReadFSLn.  Either way... I've attached code that should help you.  

ReadFSLn will read 1 one and return it has a string. Note that there is 3 things (According to ReadLN in Delphi) that determins a line.  

Hope this help you

//------------------------------------------------------------------------------
//Possible Line Combo  (LF, CR+LF, CR+EOF)
//------------------------------------------------------------------------------
function TForm1.ReadFSLn(FS: TFileStream): String;
var
  Buffer : Char;
  LastChr : Char;
begin
  //Init!
  Result := '';
  Buffer := #0;
  LastChr := #0;
  //Loop till you find the end of a line
  while FS.Position < FS.Size do //Make sure never to pass the EOF
  begin
    FS.Read(Buffer,1);
    Result := Result + Buffer;
    if (Buffer = #10) or ((LastChr = #13) and (Buffer=#10)) or (Buffer=#0) then
      exit; //Line found exit!
    LastChr := Buffer;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  FS : TFileStream;
begin
  FS := TFileStream.Create('D:\NewLog.log',fmOpenRead);
  try
    while FS.Position < FS.Size do
      Memo1.Lines.Add( ReadFSLn(FS) );

  finally
    FreeAndNil(FS);
  end;

end;
0
 

Expert Comment

by:junsom
ID: 23677840
thanks so much
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question