如何把一个project里的form加到一个dll里去??(70分)

  • 主题发起人 goldbaby
  • 开始时间
R

RedBeret

Unregistered / Unconfirmed
GUEST, unregistred user!
在DLL的PROJECT中加入这个FORM就行了
 
S

skimwater

Unregistered / Unconfirmed
GUEST, unregistred user!
在DLL的uses 后加入你的那个form所在的单元文件,然后,在exports后加入你要输出的函数。
 
G

goldbaby

Unregistered / Unconfirmed
GUEST, unregistred user!
能写的再详细些吗?如何加,
如何在另外一个窗体里调用dll
保证今天送分!
 
W

Walter

Unregistered / Unconfirmed
GUEST, unregistred user!
G

goldbaby

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
Z

zhang w.

Unregistered / Unconfirmed
GUEST, unregistred user!

{以下是动态调用dll的例子,静态调用:将dll声明为外部函数后,即可直接使用。}

/////////////////////////////{ demo.pas }////////////////////////////
unit demofrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TAboutHW=function(AppName :String):integer;Stdcall;// dll的声明

TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
aHandle :THandle;
AboutSh :TAboutHW;
begin
aHandle :=LoadLibrary('zAbout.dll');
try
if aHandle<>0 then
begin
@aboutsh:=GetProcAddress(aHandle,'AboutShow');
Caption :=InttoStr(Aboutsh(application.ExeName));
end;
finally
freeLibrary(aHandle);
end;
end;
end.

////////////////////////{ zAbout.dll }////////////////////////////

library zAbout;

{ 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
zAboutFrm in 'zAboutFrm.pas' {zAboutForm};

exports
AboutShow;

begin
end.

////////////////////{ zAboutFrm.pas,this form 选不自动创建窗体!!! }////////////
{ show form }
unit zAboutFrm;

interface

uses
Windows,SysUtils, Classes, Graphics,Forms,GIFImage, ExtCtrls, StdCtrls,
Controls;

type
TIfType=(PrcIf,OSIf);

TzAboutForm = class(TForm)
Image1: TImage;
InfoWin: TPanel;
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ FAfileName:String;
{信息显示}
Procedure IfWinCreate(InfoType :TIfType);
Procedure IfWinShow;
Procedure SetLineHW;
Procedure MakeIfRect;
Procedure FillBmp;
Procedure FreeBmp;
Procedure PaintLine(ARect:TRect;LineNum:Integer);
Procedure OnOverDo(Sender:TObject);

{显示内容}
Procedure GetMyInfo(IfType:TIfType;Var Info :TStringList);
Procedure SetPrcIf(Var Info:TStringList);
Procedure GetOSIf(Var Info:TStringList);
} public
end;

function AboutShow(AppName:String):integer;Stdcall
//必须通过函数创建form实例!!!

implementation

{$R *.DFM}

function AboutShow(AppName:String):integer;
var
zAboutForm :TzAboutForm;
begin
result :=-1;
zAboutForm :=TzAboutForm.Create(Application);
try
with zAboutForm do
begin
ShowModal;
result :=0;
end;
finally
zAboutForm.Free;
end;
end;
 
顶部