读书人

急一个简单的有关问题!多谢!(新手)

发布时间: 2012-03-12 12:45:33 作者: rapoo

急!!!!一个简单的问题!谢谢!(新手)
假如有这样一个文本文件
Ellipse 200 310 320 250 210
Line 126 210 235 301
Rectangle 230 210 320 350
我要读出它的每行,且画出相应的图形item[1]是每行第一个字符串,
if item[1]= 'Line ' then
begin
canvas.moveto(strtoint(item[2]),strtoint(item[3]));
canvas.lineto(strtoint(item[4]),strtoint(item[5]));
end;
if item[1]= 'Rectangle ' then
begin
canvas.Rectangle(strtoint(item[2]),strtoint(item[3]),strtoint(item[4]),strtoint(item[5]));
end;
if item[1]= 'Ellipse ' then
begin
canvas.Ellipse(strtoint(item[2]),strtoint(item[3]),strtoint(item[4]),strtoint(item[5]));
end;
这样循环只能画到第一个图形,我想加一个FOR循环,行数怎么求得啊


[解决办法]
for i := Low(item) to High(Item) do

还有下次不要放到非技术区
[解决办法]
假设文本文件按你提供的内容, 存储于C盘根目录下。读出后画到Form上

procedure YourProc(DrawType, R1, R2, R3, R4 : string);//这个过程实际上就是你提供的一段程序
begin
with Form1 do
begin
if DrawType= 'Line ' then
begin
canvas.moveto(strtoint(R1),strtoint(R2));
canvas.lineto(strtoint(R3),strtoint(R4));
end;
if DrawType= 'Rectangle ' then
begin
canvas.Rectangle(strtoint(R1),strtoint(R2),strtoint(R3),strtoint(R4));
end;
if DrawType= 'Ellipse ' then
begin
canvas.Ellipse(strtoint(R1),strtoint(R2),strtoint(R3),strtoint(R4));
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
F : TextFile;
S : String;
SS : TStringList;
begin
AssignFile(F, 'C:\Test.txt ');
Reset(F);
while not Eof(F) do
begin
ReadLn(F, S);
SS := TStringList.Create;
SS.Text := StringReplace(S, ' ', #10, [rfReplaceAll]);
YourProc(SS[0],SS[1],SS[2],SS[3],SS[4]);
SS.Free;
end;
CloseFile(F);
end;
[解决办法]
Var
SL , PL : TStringList;
I : Integer;
begin
Try
SL := TStringList.Create;
SL.LoadFromFile( 'aa.txt ');
For I := 0 To SL.Count - 1 Do
Begin
Try
PL := TStringList.Create;
PL.Text := StringReplace(SL.Strings[I], ' ', #10, [rfReplaceAll]);
If PL[0] = 'Line ' Then
Begin
Canvas.MoveTo(StrToInt(PL[1]),StrToInt(PL[2]));
Canvas.LineTo(StrToInt(PL[3]),StrToInt(PL[4]));
End;
If PL[0] = 'Rectangle ' Then
Begin


Canvas.Rectangle(StrToInt(PL[1]),StrToInt(PL[2]),StrToInt(PL[3]),StrToInt(PL[4]));
End;
If PL[0] = 'Ellipse ' Then
Begin
Canvas.Ellipse(StrToInt(PL[1]),StrToInt(PL[2]),StrToInt(PL[3]),StrToInt(PL[4]));
End;
Finally
PL.Free;
End;
End;
Finally
SL.Free;
End;
end;

读书人网 >.NET

热点推荐