Re: File handling



On Fri, 22 Jul 2005 07:10:38 GMT, "Loonie" <no@xxxxxx> wrote:

>I am trying to learn Delphi7,and have come to my next hurdle. I am trying
>to read a text file of G codes, that i want to draw onto a canvas. The
>trouble is i'm not sure of the best approach. The file is in the format
>
>Gstart
>G0X0Y0
>G1X100Y100
>G0X300Y500
>G1X300Y800
>etc etc
>GEnd *End of G codes*
>
>The G0 instruction is move to position, the G1 is a cut to some position.
>Now i have in place a way of reading the file line by line and adding it to
>a memo,with a button click. What i would like to do is draw the line as it
>is added, and eventually automate the process. I know i have to read
>through the line and find the Integers for X and Y, But how? And would it
>be better to read the whole file first or take the line by line approach.

This sounds a pretty strong contender for a TStringList

Have a look at: TStringList.LoadFromFile

It will load the whole lot in one go into a TStringList, you can then
get each line with:
AStringList.Strings[ Index ]
.


Quantcast