给你一个我们程序中某个dll的dpr文件, 你就知道怎么写了(设计时没必要用new..直接建立一个dll project, 完全可以先做成exe, 调试通过后再改成dll)。
library Hawb_Status;
uses
Forms,
SysUtils, // 加上一些要用到的unit
Ole2,
ADODB,
{ 下面的都是dll中的form 和 datamodule }
U_Input_HStatus in 'U_Input_HStatus.pas' {F_Input_HStatus},
U_DM_HStatus in 'U_DM_HStatus.pas' {F_DM_HStatus: TDataModule},
U_List_HStatus in 'U_List_HStatus.pas' {F_List_HStatus},
U_SaveLoadF in 'U_SaveLoadF.pas' {F_SaveLoadF},
U_SaveLoadIni in 'U_SaveLoadIni.pas' {F_SaveLoadIni},
U_Search_HStatus in 'U_Search_HStatus.pas' {F_Search_HStatus},
U_ListDef_HStatus in 'U_ListDef_HStatus.pas' {F_ListDef_HStatus},
U_SHawb_Hint in 'U_SHawb_Hint.pas' {F_SHawb_Hint},
hawblistf in 'hawblistf.pas' {ListPreview},
u_hstatus_dest in 'u_hstatus_dest.pas' {F_HStatus_dest};
{$R *.RES}
{ 供主程序调用的函数 }
function MainRunning(AUser: PChar; Privilege: Integer; WorkPath: PChar;
Conn: TADOConnection; TableName, KeyFld: PChar): Boolean; stdcall;
begin
ShortDayNames[1]:='Sun';
ShortDayNames[2]:='Mon';
ShortDayNames[3]:='Tue';
ShortDayNames[4]:='Wed';
ShortDayNames[5]:='Thu';
ShortDayNames[6]:='Fri';
ShortDayNames[7]:='Sat';
LongDayNames[1]:='Sun';
LongDayNames[2]:='Mon';
LongDayNames[3]:='Tue';
LongDayNames[4]:='Wed';
LongDayNames[5]:='Thu';
LongDayNames[6]:='Fri';
LongDayNames[7]:='Sat';
_LoginUsr := StrPas(AUser); // _LoginUsr, _TableName...都是在其他Pas中定义的全局变量
_TableName := TableName;
_UserPrivilege := Privilege;
if WorkPath = nil then
_WorkPath := ''
else
_WorkPath := StrPas(WorkPath);
CoInitialize(nil); // dll中要使用ado组件最好加上这句, 如果不加也没发觉有什么问题
F_DM_HStatus := TF_DM_HStatus.Create(Application); // 先建立datamodule
F_DM_HStatus.MainTable.KeyFldName := StrPas(KeyFld);
F_DM_HStatus.MainTable.Connection := Conn; // 将datamodule中所有的ado控件的connection置为传入的adoconnection
F_DM_HStatus.LookupQry.Connection := Conn;
F_DM_HStatus.ExecCommand.Connection := Conn;
F_DM_HStatus.adodataset1.connection := Conn;
F_Input_HStatus := TF_Input_HStatus.Create(Application); // 建立其他form
F_Search_HStatus := TF_Search_HStatus.Create(Application);
F_List_HStatus := TF_List_HStatus.Create(Application);
F_ListDef_HStatus := TF_ListDef_HStatus.Create(Application);
F_SaveLoadF := TF_SaveLoadF.Create(Application);
F_SaveLoadIni := TF_SaveLoadIni.Create(Application);
F_SHawb_Hint :=TF_SHawb_Hint.Create(Application);
lstpreview := tlstpreview.create(application);
f_hstatus_dest := tf_hstatus_dest.Create(application);
f_input_hstatus.showmodal; // 进入dll程序操作界面
FreeAndNil(F_Input_HStatus); // 调用完成后释放各form
FreeAndNil(F_Search_HStatus);
FreeAndNil(F_List_HStatus);
FreeAndNil(F_ListDef_HStatus);
FreeAndNil(F_SaveLoadF);
FreeAndNil(F_SaveLoadIni);
FreeAndNil(F_SHawb_Hint);
FreeAndNil(F_DM_HStatus);
coUnInitialize;
Result := True;
end;
exports
MainRunning name 'MainRunning';
end.