我现需要写一个dll 文件,包含这个过程或函数logconst(LogID,LogDetailID:integer;LogDec:pchar);其中LogID表示日志的大分类,LogDetailID表示日志的具体小分类(一个大类下可又若干小分类),LogDec表示日志的具体类别。然后在一个exe文件引用该dll文件,并在窗体初始化是将LogDec写进Tconbobox组件。
急用,请大侠们给点建议怎么写?
谢谢
急用,请大侠们给点建议怎么写?
谢谢
写一个dll,有一个过程logconst(LogID,LogDetailID:integer;LogDec:pchar);
一个exe文件载入这个dll文件后,调用一下dll里的这个过程,传入3个参数,其中LogID,LogDetailID是赋过值得(如:LogID=1,LogDetailID=2),LogDec这个参数没有赋值,是需要执行一下这个过程后给它赋值的,然后将赋过值得LogDec写进Tcombobox里。
如果是就这样写:
dll:
library logdll;uses
SysUtils,
Classes;
procedure Logconst(LogID,LogDetailID:integer;var LogDec:pchar);
begin
if LogID=1 then
if LogDetailID=2 then
LogDec:='1.2(第一大类之第二小类)';
end;
{$R *.res}
exports
Logconst;
begin
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TLogconst= procedure (LogID,LogDetailID:integer;var LogDec:pchar);
//需要声明dll中过程的原形
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ghandle: THandle;//dll句柄
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
gLogconst: TLogconst;//指向dll过程的指针
tmp:PChar;
begin
gHandle := LoadLibrary('logdll.dll');
if Handle <> 0 then
begin
@gLogconst := GetProcAddress(gHandle, 'Logconst');
if @gLogconst <> nil then
begin
gLogconst(1,2,tmp);
ComboBox1.Text:= tmp;
End;
end;
FreeLibrary(gHandle);
end;
end.
我这个dll是封装给别人的用的,在他调用了这个dll后(也可能是若干次连续调用),我要在我的查询界面的combobox的下拉列表上显示具体的LogDec,
而且LogID,LogDetailID,LogDec,这三个参数在调用时都已经赋值。
procedure Logconst(LogID,LogDetailID:integer;var LogDec:pchar;cbox:tcombobox);
begin
if not Assigned(cbox) then
exit;
cbox.items.add(logDec);
end;别人调用的时候必须指定一个combobox