极
极乐使者
Unregistered / Unconfirmed
GUEST, unregistred user!
我用多线程更新数据库,程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ADOTable2: TADOQuery;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function MyThreadFunc(Pointer):Longint;stdcall;
var
i:integer;
begin
form1.ADOTable2.First;
for i:=1 to 5do
begin
form1.ADOTable2.Edit;
form1.ADOTable2.FieldByName('现价').AsFloat:=6.28;
if not(form1.ADOTable2.Eof) then
form1.ADOTable2.next;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
hThread:Thandle;
ThreadIDWord;
begin
hthread:=begin
Thread(nil,0,@MyThreadfunc,nil,0,ThreadID);
if hThread=0 then
messagebox(Handle,'Didn’t Create a Thread',nil,MB_OK);
end;
end.
运行至线程函数最末时总出错,提示'access violation at XXXXXX,write of address XXXXX',请各位高手赐教,谢谢.'
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ADOTable2: TADOQuery;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function MyThreadFunc(Pointer):Longint;stdcall;
var
i:integer;
begin
form1.ADOTable2.First;
for i:=1 to 5do
begin
form1.ADOTable2.Edit;
form1.ADOTable2.FieldByName('现价').AsFloat:=6.28;
if not(form1.ADOTable2.Eof) then
form1.ADOTable2.next;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
hThread:Thandle;
ThreadIDWord;
begin
hthread:=begin
Thread(nil,0,@MyThreadfunc,nil,0,ThreadID);
if hThread=0 then
messagebox(Handle,'Didn’t Create a Thread',nil,MB_OK);
end;
end.
运行至线程函数最末时总出错,提示'access violation at XXXXXX,write of address XXXXX',请各位高手赐教,谢谢.'