在delphi中创建dll示例代码
unit frmcolor;
interface
uses
windows, messages, sysutils, classes, graphics, controls,
forms, dialogs,stdctrls, buttons, colorgrd;
type
tcolorfrm = class(tform)
colorgrid: tcolorgrid;
okbitbtn: tbitbtn;
cancelbitbtn: tbitbtn;
procedure okbitbtnclick(sender: tobject);
procedure cancelbitbtnclick(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;
var
colorfrm: tcolorfrm;
function fbcolor(var fcolor, bcolor:tcolor):wordbool;export;
implementation
{$r *.dfm}
{按 ok按钮,退出颜色对话框}
procedure tcolorfrm.okbitbtnclick(sender: tobject);
begin
modalresult := mrok;
end;
{按cancel按钮,退出颜色对话框}
procedure tcolorfrm.cancelbitbtnclick(sender: tobject);
begin
modalresult := mrcancel;
end;
function fbcolor(var fcolor, bcolor:tcolor):wordbool;
begin
result := false;
colorfrm:=tcolorfrm.create(application);
try
if colorfrm.showmodal = mrok then
with colorfrm do
begin
fcolor := colorgrid.foregroundcolor;
bcolor := colorgrid.backgroundcolor;
result := true;
end;
finally
colorfrm.free;
end;
end;
end.
library colorlib;
uses
sysutils,
classes,
frmcolor in \'frmcolor.pas\' {colorfrm};
exports
fbcolor;
{$r *.res}
begin
end.
unit testdll;
interface
uses
windows, messages, sysutils, classes, graphics, controls,
forms, dialogs, stdctrls;
type
tmainfrm = class(tform)
memo1: tmemo;
colorbtn: tbutton;
exitbtn: tbutton;
procedure colorbtnclick(sender: tobject);
procedure exitbtnclick(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;
var
mainfrm: tmainfrm;
implementation
{$r *.dfm}
{声明colorlib.dll中的函数}
function fbcolor(var fcolor, bcolor:tcolor):wordbool;far;
external \'colorlib.dll\';
{弹出colorlib.dll中的颜色对话框 }
procedure tmainfrm.colorbtnclick(sender: tobject);
var
fcolor, bcolor: tcolor;
begin
fcolor := font.color; {窗体字体颜色}
bcolor := color; {窗体背景颜色}
if fbcolor(fcolor,bcolor) then
begin
memo1.color := bcolor; {使用窗体背景色}
memo1.font.color := fcolor; {使用字体颜色}
end;
end;
procedure tmainfrm.exitbtnclick(sender: tobject);
begin
close;
end;
end.
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器