⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 用delphi编写asp的activex (2001年6月9日).txt

📁 自己对DELPHI学习的一点体会
💻 TXT
字号:
用Delphi编写ASP的ActiveX (2001年6月9日) 

本站更新  分类:DDE与OLE   作者:  推荐:   阅读次数:151  
(http://www.codesky.net)  

--------------------------------------------------------------------------------

ASP中的ActiveX服务器组件为标准的Automation ActiveX组件,只要使用由ASP提供的接口和遵守ASP有关规则便可。Delphi 4.0作为一种高效、快速、强大的开发语言,为开发COM组件提供了很强的功能,但不知道什么原因,很少有人运用Delphi编写ASP中的ActiveX服务器组件。本文意在通过举例介绍如何运用Delphi编写ASP中的ActiveX 组件。

  通过以下步骤创建ASP中的ActiveX 服务器组件: 

  1.创建一个ActiveX library工程

  打开Delphi编辑器,选择选单中的File/New,在New Item中选择 the ActiveX 项中的ActiveX Library选项,Delphi将自动生成以下代码: 

  library Project1;

  uses

   ComServ;

  exports

   DllGetClassObject,

   DllCanUnloadNow,

   DllRegisterServer,

   DllUnregisterServer;

  {$R *.RES}

  begin

  end.

  这是Delphi编译COM组件时必须的函数,DllGetClassObject函数负责将输入调用从COM库转换到相应的类工厂中;DllCanUnloadNow函数是通知OLE引擎如果没有程序引用将自动释放内存;DllRegisterServer与DllUnregisterServer函数用来登记COM服务器。总之Delphi已经为你做好了一切辅助工作,你只需用心编写主要功能模块便可。

  2.在该工程中新增一个automation对象

  选择Delphi编辑器选单中的File/New,在New Item中选择ActiveX 项中的Automation Object选项,系统将显示the Automation Object导向,在物件名称中输入TestObject和选择Multiple Instance选项,按OK键后系统将弹出类型编辑器,其实这时系统已经生成了两个单元(Project1—TLB.pas与unit1.pas),unit1.pas中有如下代码:

  initialization

   TAutoObjectFactory.Create(ComServer, TTestObject,

  Class—TestObject, ciMultiInstance);

  end.

  这是告诉类工厂物件执行的方式与位置。

  3.增加组件中的属性与方法

  在类型编辑器中单击工具栏中的方法按钮增加以下方法:

  OnStartPage(unk:IUnknown)

  OnEndPage.

  Test. 

  注意在增加方法OnStartPage时,在Parameters项中增加参数unk,类型为Iunknown,增加三项方法后,在类型编辑器中按Refrash键,Unit1.pas中将会出现三个函数,在每个函数下写如下程序:

  procedure Ttestobject.OnStartPage(unk: IUnknown);

   begin

   m_scriptContext := unk as IScriptingContext;

   end;

  procedure Ttestobject.OnEndPage;

   begin

   m_scriptContext := nil;

  end;

  procedure Ttestobject.test;

  begin

   m—scriptContext.Response.Write(′ActiveX Test For Delphi′);

  end;

  当IIS激活一个ActiveX组件时它会自动寻找组件中是否有OnStartPage与OnEndPage方法,如果存在,服务器将在开启本ASP页时自动执行OnStartPage方法和当本ASP页所有脚本执行完毕后自动执行OnEndPage方法。

  其中mscriptContext 与IScriptingContext是ASP中负责将ASP转换成HTML格式必不可少的变量与类型,因此必须将Unit1.pas文件中的Uses加上ASPTypeLibrary—TLB变成

  unit unit1;

  interface

   uses ComObj, ActiveX, Delphi_TLB, ASPTypeLibrary—TLB, SysUtils;

  ASPTypeLibrary—TLB.Pas文件可以通过类型库引入取得,打开Delphi编辑器中的选单Project/import type library 项,选择the Microsoft Active Server Pages Type library,按OK,Delphi便会自动生成一个ASPTypeLibrary_TLB.Pas。

  4.编译与注册

  选择Delphi编辑器中的选单Project/Compile 项编译文件,然后选择Run/Register ActiveX Server对Project1.dll文件注册。

  5.在ASP文件中运用Project1.dll

  在ASP文件中加入以下文字:

   Set TestASP = Server.CreateObject(Project1.TestObject)

   TestASP.Test

  通过上面的例子,我们可以发现用Delphi编写ASP中的ActiveX服务器组件是十分容易的,加上Delphi丰富的组件与强大的功能,使我们相信运用Delphi编写特殊的ASP服务器组件,如数据库、服务器上各种信息与资源访问等,都会十分方便。


Adding Bitmaps to a Tabs 



By using the TabCtrl_SetItem() meacro, adding Bitmaps to the Tabs of a PageControl or TabControl is easily accomplished. This method is preferred over making the TabControl/PageControl owner-drawn, then drawing the items yourself. 

You'll need to have an ImageList with each item corresponding to a certain Tab, or set the iImage member of the TC_ITEM struct to assign the index of the Tab's image accordingly. 

//--------------------------------------------------------------------------- 

//The goal is to change the style of each TabSheet to 
//accomodate a bitmap (TCIF_IMAGE)... 
__fastcall TForm1::TForm1(TComponent* Owner) 
: TForm(Owner) 
{ 
//Get the current Style 
DWORD dwStyle = GetWindowLong(PageControl1->Handle, GWL_STYLE); 

//Add the "put icon on left" style or TCS_FORCELABELLEFT 
//depending on where you want the image 
SetWindowLong(PageControl1->Handle, GWL_STYLE, 
dwStyle | TCS_FIXEDWIDTH | TCS_FORCEICONLEFT); 

//Change the attributes of each tab 
TC_ITEM tci; 
for (int index = 0; index < PageControl1->PageCount; index++) 
{ 
//flag the image state 
tci.mask = TCIF_TEXT | TCIF_IMAGE; 

//add the previously assigned captions 
tci.pszText = PageControl1->Pages[index]->Caption.c_str(); 

int max = PageControl1->Pages[index]->Caption.Length() * sizeof(char); 
tci.cchTextMax = max; 
tci.iImage = index; 

//force the changes 
TabCtrl_SetItem(PageControl1->Handle, index, &tci); 
} 

//associate an ImageList with the TabControl 
PageControl1->Perform(TCM_SETIMAGELIST, 0, (LPARAM)ImageList1->Handle); 
}  
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -