Re: File handling




"Loonie" <no@xxxxxx> wrote in message
news:XS5Ee.502$mk1.497@xxxxxxxxxxxxxxxxxxxxxxx
> Ok doing this by readln at the moment so this has advantages. but then how
> do i approach the problem of stripping the integers out of the line and
> using them as co-ordinates on a canvas?

First you need to define the language that is to be parsed. From the looks
of the examples you posted its something like

<command line> ::= G <verb>
<verb> ::= <start> | <move> | <end>
<start> ::= start
<end> ::= end
<move> ::= <pen state> X <integer> Y <integer>
<pen state> ::= 0 | 1

A procedure with a header some something like

Type tGCommand = (gcStart, gcEnd, gcMove);

procedure ParseGCommand (const sCmd : string;
var gCmd : tGCCommand;
var penDown : boolean;
var xPos, yPos : integer);

can be written to parse a G command input line. The code to actually parse
the line is fairly straight forward it will probably involve calls to
routines such as Uppercase, Copy, and StrToInt. One or more loops addressing
individual characters in the cmd string are likely, e.g. while cmd [i] in
['0' .. '9'] do.

You will probably need a loop to go through the lines and call ParseGCommand
as needed. It might look something like

while not EOF (someInputFile) do
begin
ReadLn (someInputFile, aLine);
if Uppercase (Copy (aLine, 1, 1)) = 'G'
then begin
ParseGCommand (Copy (aLine, 2, MaxInt), gCmd, penDown, xPos,
yPos);
case gCmd of
. . .
end;
end;
end;


Take a look at the methods of tCanvas for all you need to actually execute
the parsed commands.


.