var
f:TextFile;
headpnt,endpnt:Tpoint;
kind:string;
data1:TData;
color:TColor;
SepChar:string;///////////////////////////////////////////////////////////////////////////
Readln(f,kind,SepChar,headpnt.x,SepChar,headpnt.y,SepChar,endpnt.x,SepChar,endpnt.y,SepChar,data1.DataBaseName,SepChar,data1.TableName,SepChar,data1.FieldName,SepChar,data1.Key,SepChar,color,SepChar);
我这样读出来的各变量的类型没改变吧?那我下边要用到除了SepChar外的各量,直接应用可以不?不知道我表诉清楚没
f:TextFile;
headpnt,endpnt:Tpoint;
kind:string;
data1:TData;
color:TColor;
SepChar:string;///////////////////////////////////////////////////////////////////////////
Readln(f,kind,SepChar,headpnt.x,SepChar,headpnt.y,SepChar,endpnt.x,SepChar,endpnt.y,SepChar,data1.DataBaseName,SepChar,data1.TableName,SepChar,data1.FieldName,SepChar,data1.Key,SepChar,color,SepChar);
我这样读出来的各变量的类型没改变吧?那我下边要用到除了SepChar外的各量,直接应用可以不?不知道我表诉清楚没
f:TextFile;
headpnt,endpnt:Tpoint;
kind:string;
data1:TData;
color:TColor;
SepChar:string;只要类型不是string类型的都需要转换
var
f:TextFile;
headpnt,endpnt:Tpoint;
kind:string[255]; //必须定义字段长度
data1:TData;
color:TColor;
SepChar:string[255];
//////////
begin
...
...
BlockRead(f,kind,length(kind)); //读string
BlockRead(f,headpnt,sizeof(headpnt)) //读其他类型
...
...
end
color:=strtoint(ss[10]);
SS是我读到的串
backcolor1.bmp
seRectangle 74 100 114 140 null null null null 65280
seEchelon 246 143 286 183 null null null null 65280
seRectangle 136 54 176 94 null null null null 65280
seDiamond 210 60 250 100 null null null null 65280 不可以这样读是吧?
BlockRead(f,kind,length(kind)); //读string
BlockRead(f,headpnt,sizeof(headpnt)) //读其他类型
...
...
你这样的格式虽然用文本编辑器打开很直观,但对程序来说不是很方便
每读一行就要做分析,效率太低了
建议直接把需要的内容做成record形式,读写都很方便
例如
type
TfileInf=record
filename:string[255];
headpnt,endpnt:Tpoint;
kind:string[255]; //必须定义字段长度
data1:TData;
color:TColor;
SepChar:string[255];
end使用
//写文件
var
F:File;
fileInf:TfileInf;
begin
//录入信息
fileInf.filename='backcolor1.bmp';
fileInf.headpnt=Point(0,0);
...
...
//写入
AssignFile(F, 'C:\test.dat');
Rewrite(F);
BlockWrite(F, fileInf, sizeof(fileInf));
CloseFile(F);
end;//读出
var
F:File;
fileInf:TfileInf;
begin
AssignFile(F, 'C:\test.dat');
Reset(F);
BlockRead(F, fileInf, sizeof(fileInf));
CloseFile(F); showmessage(fileInf.filename);
end;