MC> Also, why do you think Flush is needed for a file you're
MC> about to Close (it's not.)?
DC> Pratice. I programed for a while before using Turbo Pascal, and there
DC> files needed the equivalent of a 'flush' before being closed,
DC> otherwise data was lost. Just a habbit I 'imported' from back then,
DC> flush a file before closing.
Entirely unneeded in TP/BP, so long as you explicitly Close the
output file(s) you've opened.
MC> 1. If the (input) file you're processing isn't a TP/BP Text file,
MC> then processing it that way will certainly lose data - you're using
MC> "Readln(string_var)", which means you'll only get up to 255
MC> characters of data with each logical "record i/o" - to get more,
MC> you'd need to do some other type of file/file i/o.
DC> That's exactly the problem. Many files go over the 255 line length.
Then you'll have to use untyped files and BlockRead to access
"blocks" of characters you define and work with. Much harder than Text
files and Readln, but you have non-standard data.
DC> Basically, what I want the program to do is strip the first line *if*
DC> it has certain text in it (the 'Note etc'), the rest of the file
DC> remains intact (this is only cosmetic BTW, Maximus removes the ASC 01
DC> the is before the 'Note', making that line 'visible' instead of a
DC> 'hidden' line in the message, which is mildly annoying to say the
DC> least.
MC> I suggest untyped file and BlockRead, with a fairly large buffer
MC> (say, 16K).
DC> Ok, now how would I implement that? :-)
Var Buff : array[0..16383] of Char; { 16K buffer }
F : File; { untyped file }
I : integer;
...
Assign (F,...); Reset (F,1);
repeat
BlockRead(F,Buff,SizeOf(Buff),N);
... work with N characters in buffer...
until N = 0;
Close (F)
If you don't know from this template, post another query.
MC> From that BlockRead and buffer, you'd need to develop some code to
MC> extract (unblock) data "records", according to the definition of
MC> what that file actually contains - which probably won't be records
MC> delimited by c/r & l/f pairs.
DC> It's just a text file created by an external message editor, only what
DC> appears as a paragraph on screen becomes one long line in the file -
DC> maybe a couple of thousand characters (how large is the largest
DC> paragraph you've seen?)
I don't know. Whatever it is, you can't access more than 64K...
MC> 2. Why are you using "Repeat...Until EOF" as your i/o loop? Not
MC> at all the way to do _any_ file i/o in Pascal, since you don't
MC> protect against a null file with such logic - something which will
MC> lock up or abort your program. Always the "While not EOF..." to do
MC> file i/o - no exceptions.
DC> Ok, I've not had a problem with that, although thinking about it I've
DC> probably always used the 'While' version without realising that one
DC> was better than the other.
Well, Repeat is the best way to use BlockRead, but every other kind
of file i/o should use While not EOF.
MC> 3. If you expect to construct PChar data from what you read in
MC> from this file, you can't use a Text file output file type -
MC> untyped file or "file of char" is what you want. Here again, I
MC> can't show you quite what to do, since I'm not at all sure any of
MC> this stuff is really what's needed. In fact, solving the wrong
MC> problem in some way (PChar or whatever) is likely to lead you
MC> further down an ever-expending problem "road", and I most certainly
MC> don't want to make it worse than it is.
DC> That's something I appreciate :-) All I know is, I need to be able o
DC> read in more characters, and Pchar handles more characters.
You may have to use PChar with the BlockRead code above, but you'll
still have to parse the "records" from the large block of file data you
read.
... Does The Little Mermaid wear an algebra?
--- OMX/Blue Wave/DOS v2.20
---------------
* Origin: Mike's Place (1:114/307.0)
|