線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1070
推到 Plurk!
推到 Facebook!

这有什么错?

尚未結案
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-23 17:37:26 IP:218.19.xxx.xxx 未訂閱
Procedure runselect(P:pointer);stdcall; begin adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('****'); Form2:=TForm2.Create(Application); try adoquery1.Open; except showmessage('异常处理'); end; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var thid:dword; begin createthread(nil,0,@runselect,nil,0,thid); end; 能编译,但不能执行,帮我看看吧。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-23 17:48:11 IP:147.8.xxx.xxx 未訂閱
function runselect(P:pointer): dword; stdcall; Remember to initialize COM in your thread.... BTW, why use API in creating the thread? I think you should make use of the TThread class instead...
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-10-23 17:52:35 IP:218.19.xxx.xxx 未訂閱
不好意思,我从没有写过多线程, 能给我改一改吗? 不胜感激。
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-10-23 17:57:32 IP:218.19.xxx.xxx 未訂閱
error message:'access villoation at 0x004c026e:read of address 0x0000000'
solnone
中階會員


發表:2
回覆:97
積分:69
註冊:2003-05-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-10-23 19:30:04 IP:203.66.xxx.xxx 未訂閱
'access villoation' 是因為你用的Object不存在所造成的 在Thread 中使用 COM Object 要先 CoInitialize Procedure runselect; stdcall; var adoquery1: TADOQuery; begin CoInitialize(nil); adoquery1 := TADOQuery.Create(nil); try adoquery1.ConnectionString := 'Provider=....'; adoquery1.SQL.Text := 'select * from table'; adoquery1.Open; finally adoquery1.Free; CoUninitialize(); end; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var thid: DWord; begin createthread(nil,0,@runselect,nil,0,thid); end;
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-10-24 09:08:33 IP:219.137.xxx.xxx 未訂閱
uses activex 加入 CoInitialize(nil); CoUninitialize(); 错误依旧。
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-10-24 09:34:20 IP:61.155.xxx.xxx 未訂閱
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, StdCtrls; type ado_exec = class(TThread) private Procedure runselect; { Private declarations } protected procedure Execute; override; end; type TForm1 = class(TForm) Button1: TButton; ADOQuery1: TADOQuery; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.dfm} //##################### procedure ado_exec.Execute; begin Synchronize(runselect); end; Procedure ado_exec.runselect; var adoquery1: TADOQuery; begin adoquery1:=TADOQuery.Create(nil); try adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('****'); Form2:=TForm2.Create(Application); try adoquery1.Open; except showmessage('异常处理'); end; finally adoquery1.Free; end; end; //##################### procedure TForm1.Button1Click(Sender: TObject); begin ado_exec.Create(false); end; end.
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-10-24 10:23:09 IP:219.137.xxx.xxx 未訂閱
真是见鬼了,错误依旧。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-10-24 10:41:54 IP:147.8.xxx.xxx 未訂閱
引言: 真是见鬼了,错误依旧。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-10-24 10:54:56 IP:147.8.xxx.xxx 未訂閱
I have tested... both 1) & 2) works 1) 
function RunSelect: dword; stdcall;
begin
    Result := S_OK;
end;
2) procedure RunSelect(Param: integer); stdcall; However, you should be careful that VCL is not thread safe (and same to some Windows APIs), this is an example:
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;    const
    WM_TEST = WM_USER   1;    type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure WMText(var Msg: TMessage); message WM_TEST;
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    function RunSelect: dword; stdcall;
begin
    Result := S_OK;
    SendMessage(Form1.Handle,WM_TEST,0,0);
end;    procedure TForm1.Button1Click(Sender: TObject);
var
    thid: dword;
begin
    CreateThread(nil,0,@RunSelect,nil,0,thid);
end;    procedure TForm1.WMText(var Msg: TMessage);
begin
    ShowMessage('Test');
end;    end.
solnone
中階會員


發表:2
回覆:97
積分:69
註冊:2003-05-06

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-10-26 12:37:41 IP:61.222.xxx.xxx 未訂閱
你的錯誤有二個以上! 第一: 你的錯誤訊息 'access villoation' 是因為你用的Object不存在所造成的 看起來是 adoquery1 不存在,也就是沒有 create 就用它 或是沒有指正確的物件… 第二: 在Thread 中使用 COM Object 要先 CoInitialize 請你先查第一個錯誤,是在用那一個物件方法出錯!…
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-10-27 09:46:16 IP:218.19.xxx.xxx 未訂閱
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, Activex; type TForm1 = class(TForm) ADOQuery1: TADOQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function RunSelect: dword; stdcall; var adoquery1:tadoquery; begin CoInitialize(nil); adoquery1.close; adoquery1.open; CoUninitialize(); end; procedure TForm1.Button1Click(Sender: TObject); var thid: dword; begin CreateThread(nil,0,@RunSelect,nil,0,thid); end; end. error message:error message:'access villoation at 0x00487c2a:read of address 0x0000000' 活见鬼。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-10-27 10:10:14 IP:147.8.xxx.xxx 未訂閱
Please refer to solnone's post.. You need to create ADOQuery first.
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-10-27 10:36:31 IP:218.19.xxx.xxx 未訂閱
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, Activex; type TForm1 = class(TForm) ADOQuery1: TADOQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function RunSelect: dword; stdcall; var adoquery1:tadoquery; begin CoInitialize(nil); adoquery1:=tadoquery.Create(nil); try adoquery1.close; adoquery1.ConnectionString:='Provider=***'; adoquery1.SQL.Clear; adoquery1.SQL.Add('select * from table'); adoquery1.open; finally adoquery1.free; CoUninitialize(); end; end; procedure TForm1.Button1Click(Sender: TObject); var thid: dword; begin CreateThread(nil,0,@RunSelect,nil,0,thid); end; end. 这个写table并没有open,为什么?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#15 引用回覆 回覆 發表時間:2003-10-27 10:54:43 IP:147.8.xxx.xxx 未訂閱
Proper settings of the ADOQuery (e.g. ConnectionString, SQL)?
andy_qin
一般會員


發表:41
回覆:51
積分:18
註冊:2003-03-06

發送簡訊給我
#16 引用回覆 回覆 發表時間:2003-10-27 10:59:00 IP:218.19.xxx.xxx 未訂閱
ConnectionString和SQL肯定没错, 如果我直接将adoquery1.active:=true, 则可查询数据。 adoquery1.ConnectionString:='Provider=MSDAORA.1;Password=123;User ID=123;Data Source=ho;Persist Security Info=True'; adoquery1.SQL.Add('select * from table1);
solnone
中階會員


發表:2
回覆:97
積分:69
註冊:2003-05-06

發送簡訊給我
#17 引用回覆 回覆 發表時間:2003-10-27 12:58:41 IP:203.66.xxx.xxx 未訂閱
第一種方法,直接使用 Form1.ADOQuery1 function RunSelect: dword; stdcall; begin CoInitialize(nil); Form1.ADOQuery1.close; Form1.ADOQuery1.open; CoUninitialize(); end; 第二種方法,參考到 Form1.ADOQuery1 function RunSelect: dword; stdcall; var adoquery1:tadoquery; begin adoquery1 := Form1.ADOQuery1; CoInitialize(nil); adoquery1.close; adoquery1.open; CoUninitialize(); end; 第三種方法,自已建 ADOQuery1 Procedure runselect; stdcall; var adoquery1: TADOQuery; begin CoInitialize(nil); adoquery1 := TADOQuery.Create(nil); try adoquery1.ConnectionString:='Provider=MSDAORA.1;Password=123;User ID=123;Data Source=ho;Persist Security Info=True'; adoquery1.SQL.Add('select * from table1'); adoquery1.Open; finally adoquery1.Free; CoUninitialize(); end; end;
系統時間:2024-05-10 10:57:10
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!