delphi编辑memo1的格式

来源:百度知道 编辑:UC知道 时间:2024/09/23 06:34:57
memo1中的文字格式:

1, 0, 0, 0
2, 2, 0, 0
3, 0, 2, 0
4, 2, 2, 0
5, 1, 1, -2
6, 4, 0, 0
7, 4, 2, 0
8, 3, 1, -2
9, 6, 0, 0
10, 6, 2, 0

1, line , 1, 1, 1, 2, 0
2, line , 1, 1, 1, 3, 0
3, line , 1, 1, 4, 2, 0
4, line , 1, 1, 4, 3, 0
5, line , 1, 1, 3, 5, 0
6, line , 1, 1, 4, 5, 0
7, line , 1, 1, 5, 1, 0
8, line , 1, 1, 5, 2, 0
9, line , 1, 1, 2, 6, 0

要求转换为:
line1
x1
0.000000
y1
0.000000
z1
0.000000
x2
0.000000
y2
2.000000
z2
0.000000
line2
x1
2.000000
y1
2.000000
z1
0.000000
x2
2.000000
y2
0.000000
z2
0.000000
<

TDHPoint = record
Idx:Integer;
x,y,z:Single;
end;

TDHLine = record
Idx:Integer;
T1,T2:Integer;
P1,P2:TDHPoint;
T3:Integer;
end;

var
Form1: TForm1;
PointList:array of TDHPoint;
sl,sl1:TStringList;

implementation

{$R *.dfm}

function GetPointByIdx(idx:Integer):TDHPoint ;
var
i:Integer;
begin
for i:=0 to Length(PointList)-1 do
if PointList[i].Idx=idx then
begin
Result:=PointList[i];
Exit;
end;
end;

function StrToPoint(const s:string;var P:TDHPoint):Boolean;
begin
Result:=False;
if s='' then
Exit;
sl.Clear;
try
sl.Delimiter:=',';
sl.DelimitedText:=s;
if sl.Count<>4 then
Exit;
P.Idx:=StrToInt(sl[0]);
P.x:=StrToFloat(sl[1]);
P.y:=St