Delphi多线程学习(9):多线程数据库查询(ADO)
ADO多线程数据库查询通常会出现3个问题:
1、CoInitialize 没有调用(CoInitialize was not called);所以,在使用任何dbGo对象前,必须手 调用CoInitialize和CoUninitialize。调用CoInitialize失败会产生"CoInitialize was not called"例外。
2、画布不允许绘画(Canvas does not allow drawing);所以,必须通过Synchronize过程来通知主线程访问主窗体上的任何控件。
3、不能使用主ADO连接(Main TADoConnection cannot be used!);所以,线程中不能使用主线程中TADOConnection对象,每个线程必须创建自己的数据库连接。
Delphi2007安装后在X:\Program Files\Common Files\CodeGear Shared\Data目录下有一个dbdemos.mdb文件,用来作为测试的例子。dbdemos.mdb中的customer表保存了客户信息,orders表中保存了订单信息。
测试程序流程大致是这样的:在主窗体上放TADOConnection和TQuery控件,启动时这个TQuery从Customer表中查出客户编码CustNo和公司名称Company,放到三个Combox框中,分别在三个列表框中选定客户公司名称,按照公司名称所对应的客户代码建立三个线程同时在orders表中查询销售日期SaleDate分别填入ListBox中。
{主窗体代码}
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm2 = class(TForm)
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ListBox1: TListBox;
ListBox2: TListBox;
ListBox3: TListBox;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses ADOThread;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
const
SQL_CONST='Select SaleDate from orders where CustNo = %d';
var
c1,c2,c3:Integer;
s1,s2,s3:string;
begin
//取得三个选择框客户的编码
c1:=Integ
相关文档:
实际上这个名字叫[SDL & Delphi]也不成问题, 因为除了Delphi似乎也没有哪个流行的开发工具用的是Pascal语言。
SDL其实我也只学了不到两星期而已。刚开始我想试图用VC,因为这样资料最全,也很好找,但太久没用VC现在看C的代码有点困难(->这个算符是干吗的来着……)。其实作为一个专业不是计算机的人 ......
使用delphi多年,前些天忽然遇到不会string转pbyte,很是失落,此时对于编程基本功的重要性深有体会.这其中用到MOVE函数.
使用delphi多年,前些天忽然遇到不会string转pbyte,很是失落,此时对于编程基本功的重要性深有体会.这其中用到MOVE函数.
搞了好一会才搞明白其用法.所以想贴出来帮助需要帮助的人.
var
&nb ......
需要用到的一个函数:
LONG SetWindowLong(
HWND hWnd,
int nIndex,
LONG dwNewLong
);
其中nIndex GWL_EXSTYLE Retrieves the extended window styles.
dwNewLong WS_EX_TOOLWINDOW Creates a tool window; that is, a window intended to ......
http://www.91v1.cn/bbs/read.php?tid-1797.html
我们提供的是全套,目前他们发的.社区已录制完毕.一根毛不少.
-------------------------------------------------------------------------------------------------------------------------
该教程由91v1社区免费提供.具体免费领码详情观看种子包,
--------------- ......