首页 技术 正文
技术 2022年11月20日
0 收藏 597 点赞 3,059 浏览 4996 个字

沿用上一篇Demo

环境:DelphiXE,XP,SQL2005

贴出改动过的单元代码:

dbGrid控件版:

unit SubMain_Unit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, FyDataConn_Unit, ActiveX,
ADODB, StdCtrls, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxStyles, dxSkinsCore, dxSkinBlueprint,
dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinHighContrast,
dxSkinSevenClassic, dxSkinSharpPlus, dxSkinStardust, dxSkinTheAsphaltWorld,
dxSkinVS2010, dxSkinWhiteprint, dxSkinscxPCPainter, cxCustomData, cxFilter,
cxData, cxDataStorage, cxEdit, cxNavigator, cxDBData, cxGridLevel, cxClasses,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, Grids, DBGrids; //原采用cxgrid,因动态获取全部列出错,暂时未解决,采用IDE自带的dbgridtype
TFrm_SubMain = class(TForm)
Btn_1: TButton;
Grd_2: TDBGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Btn_1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
DSet: TADODataSet;
DS: TDataSource;
Conn: TADOConnection;
{ Private declarations }
public
{ Public declarations }
end;
procedure CreateFrm(AppHnd: THandle);export;stdcall;
procedure DropFrm; export;stdcall;var
Frm_SubMain: TFrm_SubMain;implementation{$R *.dfm}
procedure CreateFrm(AppHnd: THandle);
begin
Application.Handle := AppHnd; if not Assigned(Frm_SubMain) then
Frm_SubMain := TFrm_SubMain.Create(Application); Frm_SubMain.Show;
end;procedure DropFrm;
begin
if Frm_SubMain <> nil then
FreeAndNil(Frm_SubMain);
end;
procedure TFrm_SubMain.Btn_1Click(Sender: TObject);
var
SQL: String;
begin
DSet.Connection := Conn;
DS.DataSet := DSet;
SQL := 'Select * From Cg_CgDanSub';
dbOpen(SQL,DSet); //自定义函数,用于打开数据集
Grd_2.DataSource := DS;end;procedure TFrm_SubMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TFrm_SubMain.FormCreate(Sender: TObject);
begin
Conn := TADOConnection.Create(Application);
Conn.LoginPrompt := False;
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=***;Persist Security Info=True;User ID=sa;Initial Catalog=test;Data Source=127.0.0.1';
Conn.Connected := True;
DSet := TADODataSet.Create(Application);
DS := TDataSource.Create(Application);
end;procedure TFrm_SubMain.FormDestroy(Sender: TObject);
begin
DSet.Free;
DS.Free;
FreeAndNil(Conn);
Frm_SubMain := nil;
end;
end.

cxGrid控件版:

unit SubMain_Unit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, FyDataConn_Unit, ActiveX,
ADODB, StdCtrls, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxStyles, dxSkinsCore, dxSkinBlueprint,
dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinHighContrast,
dxSkinSevenClassic, dxSkinSharpPlus, dxSkinStardust, dxSkinTheAsphaltWorld,
dxSkinVS2010, dxSkinWhiteprint, dxSkinscxPCPainter, cxCustomData, cxFilter,
cxData, cxDataStorage, cxEdit, cxNavigator, cxDBData, cxGridLevel, cxClasses,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, Grids, DBGrids,dxCore;//这边引用了一个dxCore,替换原来的dxGDIPlusAPI单元,新版本DevExpress原Com里面的配置函数转移到dxCore单元中type
TFrm_SubMain = class(TForm)
Btn_1: TButton;
GTV_1: TcxGridDBTableView;
GL_1: TcxGridLevel;
Grd_1: TcxGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Btn_1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
DSet: TADODataSet;
DS: TDataSource;
Conn: TADOConnection;
{ Private declarations }
public
{ Public declarations }
end;
procedure CreateFrm(AppHnd: THandle);export;stdcall;
procedure DropFrm; export;stdcall;var
Frm_SubMain: TFrm_SubMain;implementation{$R *.dfm}
procedure CreateFrm(AppHnd: THandle);
begin
Application.Handle := AppHnd; if not Assigned(Frm_SubMain) then
Frm_SubMain := TFrm_SubMain.Create(Application); Frm_SubMain.Show;
end;procedure DropFrm;
begin
if Frm_SubMain <> nil then
FreeAndNil(Frm_SubMain);
end;
procedure TFrm_SubMain.Btn_1Click(Sender: TObject);
var
SQL: String;
begin
DSet.Connection := Conn;
DS.DataSet := DSet;
SQL := 'Select * From Cg_CgDanSub';
dbOpen(SQL,DSet); //自定义函数,用于打开数据集
GTV_1.DataController.DataSource := DS;
(GTV_1.DataController as IcxCustomGridDataController).DeleteAllItems; //清除cxGrid列
(GTV_1.DataController as IcxCustomGridDataController).CreateAllItems(False); //添加cxGrid列,该句必须再单元后面做初始化动作end;procedure TFrm_SubMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;procedure TFrm_SubMain.FormCreate(Sender: TObject);
begin
Conn := TADOConnection.Create(Application);
Conn.LoginPrompt := False;
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=fydesign;Persist Security Info=True;User ID=sa;Initial Catalog=test;Data Source=127.0.0.1';
Conn.Connected := True;
DSet := TADODataSet.Create(Application);
DS := TDataSource.Create(Application);
end;procedure TFrm_SubMain.FormDestroy(Sender: TObject);
begin
DSet.Free;
DS.Free;
FreeAndNil(Conn);
Frm_SubMain := nil;
end;
initialization
dxInitialize;//应用dxCore单元中的该函数替换老版本DevExpress的dxGDIPlusAPI单元内的dxInitializeGDIPlus函数finalization
dxFinalize;//应用dxCore单元中的该函数替换老版本DevExpress的dxGDIPlusAPI单元内的dxFinalizeGDIPlus函数
end.

关于这段代码,同一个Dll文件中,只要输入一个窗体文件即可,其他窗体均能正常使用

initialization
dxInitialize;//应用dxCore单元中的该函数替换老版本DevExpress的dxGDIPlusAPI单元内的dxInitializeGDIPlus函数finalization
dxFinalize;//应用dxCore单元中的该函数替换老版本DevExpress的dxGDIPlusAPI单元内的dxFinalizeGDIPlus函数

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,906
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727