This example shows the process of saving data in a path to a text file and then reading it again.
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls;
Type
TForm1 = Class (Tform)
Button1:tbutton;
Button2:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Const
FilePath = ' c:\temp\path.txt ';
Var
Path:tgpgraphicspath;
P:tgppen;
Procedure Tform1.formcreate (Sender:tobject);
Var
PTS:ARRAY[0..6] of Tgppoint;
Rect:tgprect;
Begin
Pts[0]. X: = 10; Pts[0]. Y: = 50;
PTS[1]. X: = 40; PTS[1]. Y: = 90;
PTS[2]. X: = 80; PTS[2]. Y: = 10;
PTS[3]. X: = 110; PTS[3]. Y: = 50;
PTS[4]. X: = 140; PTS[4]. Y: = 10;
PTS[5]. X: = 180; PTS[5]. Y: = 90;
PTS[6]. X: = 210; PTS[6]. Y: = 50;
Path: = Tgpgraphicspath.create;
Path. AddBeziers (Pgppoint (@pts), Length (pts));
Path. GetBounds (rect);
Path. AddEllipse (rect);
P: = Tgppen.create (Aclblue, 2);
Button1.caption: = ' save path data ';
Button2.caption: = ' read path data ';
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Path. Free;
P.free;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
Begin
G: = Tgpgraphics.create (Canvas.handle);
G.drawpath (P, path);
G.free;
End
Procedure Tform1.button1click (Sender:tobject);
Var
Points:array of Tgppoint;
Types:array of Byte;
List:tstringlist;
I:integer;
Begin
SetLength (points, path.) Getpointcount);
SetLength (types, path.) Getpointcount);
Path. Getpathpoints (Pgppoint (points), Length (points));
Path. Getpathtypes (Pbyte (types), Length (types));
List: = tstringlist.create;
For I: = 0 to Length (points)-1 do
List.add (Format ('%d,%d,%d ', [points[i]. X, Points[i]. Y, Types[i]]);
List.savetofile (FilePath);
List.free;
Text: = FilePath;
End
Procedure Tform1.button2click (Sender:tobject);
Var
Points:array of Tgppoint;
Types:array of Byte;
List1,list2:tstringlist;
I:integer;
Begin
List1: = tstringlist.create;
List2: = tstringlist.create;
If not fileexists (FilePath) then Exit;
List1.loadfromfile (FilePath);
SetLength (points, list1.count);
SetLength (types, list1.count);
For I: = 0 to List1.count-1 do
Begin
If list1[i] = ' then break;
List2.commatext: = List1[i];
Points[i]. X: = Strtointdef (List2[0], 0);
Points[i]. Y: = Strtointdef (list2[1], 0);
Types[i]: = Strtointdef (list2[2], 0);
End
Path. Reset;
Path. Free;
Path: = Tgpgraphicspath.create (Pgppoint (points), pbyte (types), list1.count);
P.setcolor (aclred);
Repaint;
List1.free;
List2.free;
End
End.