procedure TForm1.Button1Click(Sender: TObject);
var
TextFileVar: Textfile ;
fileN: string;
id, hz,bm,temp: string;
begin
FileN:='hanzi.txt';
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
table1.open;
table1.edit;
while not SeekEof(TextFileVar) do
begin
Readln ( TextFileVar , temp ) ;
id:=copy(temp, 1, pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
hz:=copy(temp, 1, pos(' ',temp)-1);
bm:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
table1.append;
table1.fields[0].AsInteger:=StrToInt(id);
table1.fields[1].AsString:=hz;
table1.fields[2].AsString:=bm;
end;
table1.post;
closeFile(TextFileVar);
end;转自大富翁论坛
var
TextFileVar: Textfile ;
fileN: string;
id, hz,bm,temp: string;
begin
FileN:='hanzi.txt';
AssignFile ( TextFileVar , FileN ) ;
Reset(TextFileVar);
table1.open;
table1.edit;
while not SeekEof(TextFileVar) do
begin
Readln ( TextFileVar , temp ) ;
id:=copy(temp, 1, pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
hz:=copy(temp, 1, pos(' ',temp)-1);
bm:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
table1.append;
table1.fields[0].AsInteger:=StrToInt(id);
table1.fields[1].AsString:=hz;
table1.fields[2].AsString:=bm;
end;
table1.post;
closeFile(TextFileVar);
end;转自大富翁论坛
解决方案 »
- DBGridEhDrawColumnCell 方法取数值????
- 两个BMP图片,大的图片作背景,小的图片叠在其上面,如何在背景图片上截取小图片面积一样大小的一块呢?
- 怎样用Table控件完成TitleButtonClick排序?
- ODAC连接Oracle数据库时的问题
- 为何我的客户端连接的应用程序服务器出问题后,Simpleobjectbroker不能给它指定一服务器呢?
- 怎样把主窗口上的Caption字体从右向左移动
- 我快要疯了!更改了自定义控件的属性名称后,再引用时却还是以前的,怎么办?up有分!
- 如何实现程序中调用ALTER、BACKUP等命令。
- 怎么样使程序只运行一个实例?
- 帮帮我好吗????
- 如何设置用ADOConnection连接带有密码的SQL Server,ADOConnection哪个属性需要设置?急!!!!!
- 查询数据速度为什么这么慢?
文本行与stringgrid行一致;
在文本中遇到空格则放入下一cells.
rocedure TForm1.Button1Click(Sender: TObject);
var
aa,bb:tstringlist;
i:integer;
begin
aa:=tstringlist.Create;
bb:=tstringlist.Create;
aa.LoadFromFile('c:\windows\desktop\aa.txt');
for i:=0 to aa.Count-1 do
begin
bb:=SplitString(aa.Strings[i],' ');
stringgrid1.Rows[i]:=bb;
end;
aa.Free;
bb.Free;
end;其中splitstring为:
function SplitString(const source,ch:string):tstringlist;
var
temp:string;
i:integer;
begin
result:=tstringlist.Create;
temp:=source;
i:=pos(ch,source);
while i<>0 do
begin
result.Add(copy(temp,0,i-1));
delete(temp,1,i);
i:=pos(ch,temp);
end;
result.Add(temp);
end;