沿用上一篇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. wap资费页面

    移动网关 CMWAP 返回vnd.wap.wml 用CMWAP接入点发一个http的请求时,移动的10.0.0.172这个代理网关会回一个确认页面,中国特色.处理的办法是检测到Content-type ...

  2. 共享有线实现手机上网,然后使用charles来抓包

    问题描述:共享有线实现手机上网(http://support1.lenovo.com.cn/lenovo/wsi/htmls/detail_1323385217890211.html)  [建议] 还 ...

  3. windows下如何使用makefile编译

    1. 编写makefile. 2. 使用nmake进行编译, vs2010或者其他都是用nmake进行编译的,将bin目录添加到path环境变量中 先执行vcvars32.bat 再执行nmake

  4. android 如何设置背景的透明度

    半透明<Button android:background="#e0000000" ... />透明<Button android:background=&quo ...

  5. 解决Cannot find or open the PDB file问题

    今天使用opencv里的mat想要保存数据里边的像素的平均值和标准差: 但是编程好了之后会出现下面的问题,不能找到pdb file .下面将提供三种解决方法以及产生问题的原因. 程序也运行不出来,整个 ...

  6. Genymotion中文手册(官方用户手册翻译)

    目录 1.概述    2 2.特点    2 2.1最擅长于虚拟Android    2 2.2高可控性    2 2.3管理你的设备    2 2.4从Eclipse中开启虚拟设备    3 3.要 ...

  7. TCP/IP详解学习笔记(7)-- 初识运输层

    作为TCP和UDP协议的学习前奏,简单的介绍一下运输层的相关内容,方便对TCP,UDP的学习. 1.概述      运输层的任务主要是负责主机中两个进程之间的通信.      运输层的基本功能: 复用 ...

  8. SQL:认识数据库约束

    讲了关于数据库的很多内容,也讲了很多约束,对唯一和主键.核查和规则.外键约束很感兴趣. 一.唯一和主键(实体完整性) 区别: 数量:一张表只可以有一个主键约束,却可以有多个唯一约束. 是否空值:主键不 ...

  9. PAT1020. Tree Traversals

    //典型后中省树,这种方法必须有 中序序列来确定根的位置,然后二分建树: //因为用的vc,之前用序列位置建树通不过,用坐标建树通过了,怀疑vc的功能限制,有时间再来测试,眼下感觉还是坐标好啊,用地址 ...

  10. sqlplus sys/system@'(description=(address_list=(address=(protocol=tcp)(host=192.168.11.199)(port=1521)))(connect_data=(service_name=byRuiy)))' as sysdba