ifs.position=ifs.size (true if eof) Jangita. http://www.jangita.com mailto:[EMAIL PROTECTED]
-----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Rob Kennedy Sent: 22 December 2005 2:41 a To: [email protected] Subject: Re: [delphi-en] TFileStream - How to test for End-Of-File condition? kc0fcp wrote: > In C++, the ifstream class has a property "eof", that seems to be the > default property. I'm porting come C++ code to Delphi, and it has a > form like: > > ifstream ifs( pszFile, ios::binary|ios::nocreate|ios::in ); > if( ! ifs ) { handle error} > ifs.read( (BYTE*)&structure, sizeof(structure) ); > if( ! ifs ) {handle error} > > > How is this supposed to be done in Delphi? I don't find any property > or method that gives the EOF indication. The EOF function in the > System unit applies only to the older assign/reset/rewrite style of > file access. How is EOF tested when using TFileStream? Well, there's the obvious check: Is the Position property equal to the Size property? Also, you can check the return value of the Read method. If it doesn't read as much as you asked for, then you must have reached the end. The ReadBuffer method will check the amount read for you, and if it's not as much as you asked for, it will raise an exception for you to handle later. > I guess I could re-write everything with AssignFile, Reset, BlockRead, > and EOF, but I thought TFileStreams were supposed to be a better way > to handle files? There's nothing inherent to a TFileStream that makes it better than the standard Pascal functions. However, TFileStream descends from TStream, so if you already know how to use TStream, then you automatically know how to use TFileStream (and TResourceStream, and TMemoryStream, and TStringStream, and whatever else you encounter). For that reason, I've never bothered to learn how to use AssignFile and Reset. -- Rob ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Yahoo! Groups Links ------------------------ Yahoo! Groups Sponsor --------------------~--> 1.2 million kids a year are victims of human trafficking. Stop slavery. http://us.click.yahoo.com/WpTY2A/izNLAA/yQLSAA/i7folB/TM --------------------------------------------------------------------~-> ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/delphi-en/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

