Hi
I've built a simple VCL that modifies a line of text (CNC G-Code) and displays result in a label. Now that the code is working ok, I want to use the same code to modify a g-code file loaded into a tmemo.
I am having some trouble wih this. How do I get the program to move line by line through the file modifing each line in turn ?
I tried to load the contents of the memo to a Tstringlist without success but I don't know whether or not this is the right approach. My failed attempt below.
Any help would be appreciated. Thanks.
Using Turbo Delphi.
I've built a simple VCL that modifies a line of text (CNC G-Code) and displays result in a label. Now that the code is working ok, I want to use the same code to modify a g-code file loaded into a tmemo.
I am having some trouble wih this. How do I get the program to move line by line through the file modifing each line in turn ?
I tried to load the contents of the memo to a Tstringlist without success but I don't know whether or not this is the right approach. My failed attempt below.
Any help would be appreciated. Thanks.
Using Turbo Delphi.
Code:
procedure TForm1.btnRunClick(Sender: TObject);
var
source : tstringlist;
I: Integer;
OldValue, NewValue : String;
Radius: Extended;
begin
source := tstringlist.Create;
Source := Memo1.text;
Radius := StrtoFloat(Edit1.text);
if source = '' then
Begin
Showmessage('No File loaded.');
Exit;
end
else
for i := 0 to Memo1.Lines.Count-1 do
// Following code works OK when taking one line of text from an editbox
// but how to deal with every line in turn loaded into a TMemo ?
begin
if ansicontainsstr (Source,'X') then
if HasUnwanted(['A','B','Y','F','H','D'],Source) then
begin
OldValue := GetXMove(Source);
NewValue := 'B' + Convert(OldValue,Radius);
end
else
begin
OldValue := AnsiMidstr(source,(ansipos('X',Source)),maxint);
NewValue := 'B' + Convert(OldValue,Radius);
end;
NewValue := AnsiReplaceStr(source,(OldValue), (NewValue));
end;
end;