Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing readln and writeln in a Windowed App.

Status
Not open for further replies.

FrankThynne

Technical User
May 29, 2001
36
GB
Are there standard ways of replacing the functionality of textfiles which work in console apps but not windowed apps? It's readln that I'd rather not re-implement!
 
Using Readln to read from textfiles isn't console specific; you can use it in windowed apps.
 
In fact you might want to in some situations.
You could try to use the loadfromfile method of certain componets/controls, TStrings, TStringList, but this may introduce a lot of unnessacary overhead.
Steve
 
MikeEd: I quote from the Object Pascal reference manual:
Note: Text-oriented I/O is available only in console applications—that is, applications compiled with the “Generate console application” option checked on the Linker page of the Project Options dialog box or with the -cc command-line compiler option. In a GUI (non-console) application, any attempt to read or write using Input or Output will produce an I/O error.

I inadvertantly tried writeln(File, var, ...) after moving from a console app to a GUI app and had I/O errors - and then saw the above warning in the manual. It's possible that I was trying to use the implied Output file (and it makes sense that you can't use Input or Output in a GUI app) but the manual in unequivocal in its warning about text-oriented I/O in general.

sggaunt: Thanks but, as you suspect, I don't want the overhead of loading the whole file at once.

I've since written a crude routine to emulate readln, but still wonder if I had to bother!
 
Well, as you say, reading from/writing to standard output obviously won't work but, trust me, text oriented file IO works fine. Provided you've correctly opened the file for writing that shouldn't cause a problem.
 
Mike is right
However I belive there is a mistake in the help files relating to this that might be throwing you off (Honest).
but I cant find it today!! I seem to remember it is a Wrong file variable type assignment.

I have code based on the readln help example that works fine. The file variable here assigned as
var F: TextFile;

Steve
 
Thanks Mike and Steve. I'm sure you're right. It makes no sense for readln and writeln to fail with disk files - and a lot of sense for Input and Output not to work in a GUI application. I suspect that the manual writer made an incorrect inference from the latter. I should have looked at my failed code (now erased) more closely - there must have been another error that misled me.
 
No, I think the manual is just referring to standard input/output and not text IO in general.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top