DLL问题(50分)

  • 主题发起人 主题发起人 狄克
  • 开始时间 开始时间

狄克

Unregistered / Unconfirmed
GUEST, unregistred user!
我想要一个完整的DLL例子,最好带数据集示例
 
搜搜以前的帖子吧。
有不少哩。
 
好吧,既然要例子,我就给你贴代码吧,准备好了啊...一大驮...
 
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, StdCtrls, Buttons,
ExtCtrls,Forms, ComCtrls,DateUtils, Grids, Controls, Wwdbigrd,
Wwdbgrid, DBTables, DB, wwcheckbox;
type
TFormMain = class(TForm)
Panel1: TPanel;
tbApplysub: TTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
Database1: TDatabase;
wwExpandButton1: TwwExpandButton;
qryApply: TQuery;
Label1: TLabel;
GroupBox1: TGroupBox;
edBillno: TEdit;
Label2: TLabel;
Label3: TLabel;
dtpApplytime: TDateTimePicker;
Label4: TLabel;
cmbMan: TComboBox;
qrySearch: TQuery;
StatusBar1: TStatusBar;
btnVoid: TButton;
btnDelete: TButton;
Button4: TButton;
wwDBGrid1: TwwDBGrid;
wwDBGrid2: TwwDBGrid;
wwDBGrid2IButton: TwwIButton;
Label6: TLabel;
cbifdraw: TCheckBox;
cbifvoid: TCheckBox;
btnSeek: TButton;
Label5: TLabel;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cmbManCloseUp(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure rbwlClick(Sender: TObject);
procedure btnSeekClick(Sender: TObject);
procedure edBillnoKeyPress(Sender: TObject;
var Key: Char);
procedure qryApplyAfterScroll(DataSet: TDataSet);
procedure btnVoidClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure cbifdrawClick(Sender: TObject);
private
procedure SeekBill;
{ Private declarations }
public
{ Public declarations }
end;

var
FormMain: TFormMain;
procedure lib_apply(Hnd:THandle);export;
implementation
{$R *.dfm}
procedure lib_apply(Hnd:THandle);export;
begin
try
Application.Handle:=Hnd;
FormMain:=TFormMain.Create(Application);
FormMain.ShowModal;
finally
FormMain.Free
end;
//
end;

procedure TFormMain.Button4Click(Sender: TObject);
begin
Close;
end;

procedure TFormMain.FormCreate(Sender: TObject);
begin
DataBase1.Connected:=true;
qryApply.DatabaseName:=Database1.DatabaseName;
qrySearch.DatabaseName:=Database1.DatabaseName;
tbApplysub.DatabaseName:=Database1.DatabaseName;
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('select EmployeeNo,EmployeeName from pbemployee order by EmployeeNo');
qrySearch.Open;
cmbMan.Items.Clear;
cmbMan.Items.Add('(全部)');
while not qrySearch.Eof do
begin
cmbMan.Items.Add(qrySearch.fieldbyname('EmployeeNo').AsString+'-'+qrySearch.fieldbyname('EmployeeName').AsString);
qrySearch.Next;
end;
cmbMan.ItemIndex:=0;
dtpApplyTime.DateTime:=IncYear(dtpApplyTime.DateTime,-1);
end;

procedure TFormMain.cmbManCloseUp(Sender: TObject);
begin
Caption:=Copy(cmbMan.Text,1,pos('-',cmbMan.Text)-1);
end;

procedure TFormMain.SeekBill;
begin
qryApply.Close;
qryApply.SQL.Clear;
qryApply.SQL.Add('select (select ''buttons'') a,billno,p1.employeename applier,applytime,');
qryApply.SQL.Add('p2.employeename passer,p3.employeename cwpasser,ifpass,ifdraw,ifcwpass,ifvoid,memo from wlapplymaster a ');
qryApply.SQL.Add(' left join pbemployee p1 on p1.employeeno=a.applier ');
qryApply.SQL.Add(' left join pbemployee p2 on p2.employeeno=a.passer ');
qryApply.SQL.Add(' left join pbemployee p3 on p3.employeeno=a.cwpasser ');
qryApply.SQL.Add(' where a.ifcar=0 ');
if cbifdraw.Checked then
qryApply.SQL.Add(' and a.ifdraw=0 ');
if cbifvoid.Checked then
qryApply.SQL.Add(' and a.ifvoid=0 ');
if cmbMan.ItemIndex>0 then
qryApply.SQL.Add(' and a.applier='''+Copy(cmbMan.Text,1,pos('-',cmbMan.Text)-1)+'''');
qryApply.SQL.Add(' and a.billno like :billno and a.applytime>:applytime ');
qryApply.SQL.Add(' order by a.billno ');
qryApply.ParamByName('billno').AsString:='%'+ edbillno.Text+'%';
qryApply.ParamByName('applytime').AsDateTime:=dtpapplytime.DateTime;
qryApply.Open;
tbApplysub.Open;
end;

procedure TFormMain.FormShow(Sender: TObject);
begin
SeekBill;
end;

procedure TFormMain.rbwlClick(Sender: TObject);
begin
SeekBill;
end;

procedure TFormMain.btnSeekClick(Sender: TObject);
begin
SeekBill;
end;

procedure TFormMain.edBillnoKeyPress(Sender: TObject;
var Key: Char);
begin
IF Key=#13 then
begin
btnSeek.SetFocus;
btnSeek.Click;
end;
end;

procedure TFormMain.qryApplyAfterScroll(DataSet: TDataSet);
begin
// 1:=not ((1 xor 1) or (0 or 0)) //没有审核或全部通过审核 //而且没有领用也没有作废
btnVoid.Enabled:=not ((qryApply.FieldByName('ifpass').AsBoolean xor qryApply.FieldByName('ifcwpass').AsBoolean) or (qryApply.FieldByName('ifdraw').AsBoolean or qryApply.FieldByName('ifvoid').AsBoolean));
// 1:=not ((1 xor 1) or 0)
btnDelete.Enabled:=not ((qryApply.FieldByName('ifpass').AsBoolean xor qryApply.FieldByName('ifcwpass').AsBoolean) or qryApply.FieldByName('ifdraw').AsBoolean );
end;

procedure TFormMain.btnVoidClick(Sender: TObject);
begin
if Messagebox(Handle,'是否要作废这条物料申请单?','',MB_YESNO+MB_ICONQUESTION)=IDYES then
begin
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('update wlapplymaster set ifvoid=1 where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.ExecSQL;
Messagebox(Handle,'作废成功!','',MB_OK+MB_ICONINFORMATION);
btnSeek.SetFocus;
btnSeek.Click;
end;
end;

procedure TFormMain.btnDeleteClick(Sender: TObject);
begin
if Messagebox(Handle,'是否要删除这条物料申请单?','',MB_YESNO+MB_ICONQUESTION)=IDYES then
begin
qrySearch.Close;
qrySearch.SQL.Clear;
qrySearch.SQL.Add('begin
TRANSACTION ');
qrySearch.SQL.Add('delete from wlapplydetail where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.SQL.Add('delete from wlapplymaster where billno='''+qryApply.FieldByName('billno').AsString+'''');
qrySearch.SQL.Add('commit ');
qrySearch.ExecSQL;
Messagebox(Handle,'删除成功!','',MB_OK+MB_ICONINFORMATION);
btnSeek.SetFocus;
btnSeek.Click;
end;
end;

procedure TFormMain.cbifdrawClick(Sender: TObject);
begin
btnSeek.Click;
end;

end
上面是我以前写的一个物料申请单作废的外挂DLL,代码粗糙情见凉,不过你可以看看写dll的要点
 
这是工程文件
library Plibapply;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
uMain in 'uMain.pas' {FormMain};
{$R *.res}
exports
lib_apply;
begin
end.
 
下面是调用的代码:
procedure TfrmMain.applyClick(OutlookList: TfcCustomOutlookList;
Item: TfcOutlookListItem);
type TProc = procedure(Hnd:THandle);
var
hnd:Thandle;
Proc:TProc;
begin
if FileExists('Plibapply.dll') then
begin
hnd:=LoadLibrary('Plibapply.dll');
Proc:=GetProcAddress(hnd,'lib_apply');
Proc(Handle);
FreeLibrary(hnd);
end
else
MessageBox(Handle,'没有找到动态链接库文件Plibapply.dll,无法运行','',MB_OK+MB_ICONWARNING);
end;
 
嘿嘿,一大驼,窗体文件就不用我贴了吧,要不大家会拿鸡蛋扔我....其实我最讨厌贴代码的了
 
我的例子已经发给楼主了,解决了DLL大多数的问题!呵呵!
楼主我来拿分了,
 
to zyg_zm
你的例子只是一般的方法存在很多问题!
 
to Dinky:请指教:????
 
to zyg_zm
你好,对不起我说你的调用方法只是一般,
我对你的调用方法看出以下缺点
第一在主窗体中不能得到子窗体的个数,应该在调用时传递Screen参数.
不过DLL总是有很多问题,希望与你多多交流,
QQ:185511468

 
不好意思,我没说清楚,我上面贴的调用代码是指调用我上面那个DLL代码,没有用到子窗体。
 
多人接受答案了。
 
后退
顶部