关于添加数据的问题。 ( 积分: 50 )

  • 主题发起人 主题发起人 nq961
  • 开始时间 开始时间
N

nq961

Unregistered / Unconfirmed
GUEST, unregistred user!
看多线程快半个月了,还是一塌糊涂,谁能帮帮我呢?
帮我把下面的线程改成多线程呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
filename,temp,t1,t2,t3,t4:string;
f:textfile;
begin
filename:='c:/year.txt';
assignfile(f,filename);
reset(f);
while not eof(f)do
begin
readln(f,temp);
if pos(' ',temp)>0 then
begin
t1:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t2:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t3:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t4:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end
else
t4:=temp;

with adoquery1do
begin
close;
sql.Clear;
sql.Add('insert into biao (nam,pwd,lx,ly) values (:a,:b,:c,:d)');
parameters.ParamByName('a').Value:=t1;
parameters.ParamByName('b').Value:=t2;
parameters.ParamByName('c').Value:=t3;
parameters.ParamByName('d').Value:=t4;
execsql;
end;
end;
end;

end.

year.txt 文件格式如下:
11.2 23.2 22.4 4l.2
34.2 23.2 35.3 33.3
45.5 53.6 66.4 46.4
42.4 64.3 75.4 42.4
 
看多线程快半个月了,还是一塌糊涂,谁能帮帮我呢?
帮我把下面的线程改成多线程呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
filename,temp,t1,t2,t3,t4:string;
f:textfile;
begin
filename:='c:/year.txt';
assignfile(f,filename);
reset(f);
while not eof(f)do
begin
readln(f,temp);
if pos(' ',temp)>0 then
begin
t1:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t2:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t3:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
if pos(' ',temp)>0 then
begin
t4:=copy(temp,1,pos(' ',temp)-1);
temp:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end
else
t4:=temp;

with adoquery1do
begin
close;
sql.Clear;
sql.Add('insert into biao (nam,pwd,lx,ly) values (:a,:b,:c,:d)');
parameters.ParamByName('a').Value:=t1;
parameters.ParamByName('b').Value:=t2;
parameters.ParamByName('c').Value:=t3;
parameters.ParamByName('d').Value:=t4;
execsql;
end;
end;
end;

end.

year.txt 文件格式如下:
11.2 23.2 22.4 4l.2
34.2 23.2 35.3 33.3
45.5 53.6 66.4 46.4
42.4 64.3 75.4 42.4
 
把TForm1.Button1Click的内容写进线程的执行事件中去,至于ADO部分注意初始化和用完以后释放,请参考DFW里的内容,另外注意下,DFW里大部分讲的是在线程的DESTROY事件里释放ADOQUERY和ADOCONNECTION,而我在用的时候发现不能释放,建议将释放部分放在线程执行过程的内容里。
 
我还是明白,谁能够帮我写一下呢
 

Similar threads

I
回复
0
查看
569
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部