沿用上一篇Demo

环境:DelphiXE,XP,SQL2005

贴出改动过的单元代码:

dbGrid控件版:

unit SubMain_Unit;

interface

uses
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自带的dbgrid type
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;

interface

uses
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函数

Dll学习二_Dll 窗体中动态创建数据并使用Demo的更多相关文章

  1. laravel在控制器中动态创建数据表

    Schema::connection('usertable')->create('test', function ($table) { $table->increments('id'); ...

  2. Delphi中动态创建窗体有四种方式

    Delphi中动态创建窗体有四种方式,最好的方式如下: 比如在第一个窗体中调用每二个,主为第一个,第二个设为动态创建 Uses Unit2; //引用单元文件 procedure TForm1.But ...

  3. WPF 中动态创建和删除控件

    原文:WPF 中动态创建和删除控件 动态创建控件 1.容器控件.RegisterName("Name",要注册的控件)   //注册控件 2.容器控件.FindName(" ...

  4. python中动态创建类

    class Foo(Bar): pass Foo中有__metaclass__这个属性吗?如果是,Python会在内存中通过__metaclass__创建一个名字为Foo的类对象(我说的是类对象,请紧 ...

  5. 在DELPHI中动态创建控件以及控件的事件

    在DELPHI中我们经常要动态的创建控件以及控件的事件.例如,我们可能想根据程序需要动态的创建一些Tshape组件来创建某个图形,并使得在鼠标移动上去之后可以完成某些操作.这一般需要需要三步: 生成一 ...

  6. jQuery中动态创建、添加元素的方法总结

    <input type="button" value="创建元素" id="btn"> <div id="box ...

  7. WPF 中动态创建、删除控件,注册控件名字,根据名字查找控件

    动态创建控件 1.容器控件.RegisterName("Name",要注册的控件)   //注册控件 2.容器控件.FindName("Name") as  控 ...

  8. 《DOM Scripting》学习笔记-——第七章 动态创建html内容

    本章内容: 1.动态创建html内容的“老”技巧:document.write()和innerHTML属性 2.DOM方法:createElement(),creatTextNode(),append ...

  9. BroadcastReceiver接收电量变化的广播-------在代码中动态创建接受者

    本例为动态创建广播接收者即不是在AndroidManifest.xml文件中定义的广播接收着 代码: package com.qf.broadcastreceiver01; import androi ...

随机推荐

  1. LayoutInflater的实例化

    获得 LayoutInflater 实例的三种方式 1. LayoutInflater inflater = getLayoutInflater();  //调用Activity的getLayoutI ...

  2. adb bugreport > d:/bug.txt

    adb bugreport > d: 快速下载anr等bug日志

  3. 数据以Excel形式导出导服务器,再将文件读取到客户端另存 以HSSFWorkbook方式实现

    public void exportExcel(List<P2pInfo> repayXist,HttpServletRequest request,HttpServletResponse ...

  4. Android——显示单位px和dip以及sp的区别

    dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖像素.d ...

  5. HttpWebRequest访问时,错误:(401)未经授权。

    HttpWebRequest访问时,错误:(401)未经授权. 某网页,我不想做登录界面,直接使用域的帐号密码来访问.如果网站设置成Window身份验证,单独的页面都没问题,而是通过使用HttpWeb ...

  6. Unity Shader:Blur

    花了一晚上的时间终于看懂Image Effect中的Blur,其实很简单,就是一下子没有理解到. 原理:使用两个一维[1*7]的高斯滤波模板,一个用在x方向,另一个用在y方向.高斯滤波有模糊的效果. ...

  7. Flex4+BlazeDS+JAVA+MySql 构建J2EE工程 对用户信息进行管理实例

    要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...

  8. cygwin中运行命令提示command not found的解决方法

    在cygwin下运行ls等linux常见命令时出现“command not found”的提示,原因是环境变量没有配置好,因此只要将环境变量配置正确,即可正常使用.举例说明,cygwin安装在C盘根目 ...

  9. org.springframework.jdbc.BadSqlGrammarException

    org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLExc ...

  10. 学习练习 java数据库查询小题

    10. 查询Score表中的最高分的学生学号和课程号.(子查询或者排序) 11. 查询每门课的平均成绩. 12.查询Score表中至少有5名学生选修的并以3开头的课程的平均分数. 13.查询分数大于7 ...