admin 管理员组文章数量: 1184232
效果图
参考
利用DLL实现窗体的重用
在 Delphi 5 中,通过 DLL(动态链接库)实现窗体的重用是一种高级技术,它允许你在多个应用程序之间 共享窗体代码 。这通常用于减少代码冗余,提高开发效率,并允许模块化设计。
步骤1 设计出理想窗体
像平时一样设计一个窗体,调试运行成功。
{将左边选中的移到右边}
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i:=ListBox1.Items.Count-1 downto 0 do
begin
if ListBox1.Selected[i] then
begin
ListBox2.Items.Add(ListBox1.Items[i]); //加到另外框
ListBox1.Items.Delete(i); //删除选中
end;
end;
end;
{将左边全部移到右边}
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
// 遍历ListBox1中的所有项
for i := 0 to ListBox1.Items.Count - 1 do
begin
// 将ListBox1中的项添加到ListBox2中
ListBox2.Items.Add(ListBox1.Items[i]);
end;
// 如果你希望清空ListBox1,可以在这里执行
ListBox1.Items.Clear;
end;
{将右边选中的移到左边}
procedure TForm1.Button3Click(Sender: TObject);
var
i: Integer;
begin
for i:=ListBox2.Items.Count-1 downto 0 do
begin
if ListBox2.Selected[i] then
begin
ListBox1.Items.Add(ListBox2.Items[i]); //加到另外框
ListBox2.Items.Delete(i); //删除listbox中选中的
end;
end;
end;
{将右边全部移到左边}
procedure TForm1.Button4Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ListBox2.Items.Count - 1 do
begin
ListBox1.Items.Add(ListBox2.Items[i]);
end;
ListBox2.Items.Clear;
end;
{点击确定}
procedure TForm1.Button5Click(Sender: TObject);
begin
modalresult:=mrOK;
end;
{点击取消}
procedure TForm1.Button6Click(Sender: TObject);
begin
modalresult:=mrCancel;
end;
步骤2 编写一个用户输出的函数或过程,在其中对窗体进行创建使它实例化
var
Form1: TForm1;
function ListMove(var l1,l2:Integer):wordbool;export; //让外部调用
{返回选中了几门课程}
function ListMove(var l1,l2:Integer):wordbool;
begin
result:=False;
Form1:=TForm1.create(Application); //调用这个DLL时,创建窗体(实例化)
try
if Form1.showmodal=mrOk then //点击确定
with Form1 do
begin
l1:=listbox1.items.count;
l2:=listbox2.items.count;
result:=True;
end;
finally
Form1.free;
end;
end;
步骤3 对工程文件进行相应的修改以适应DLL格式的需要
//program Project1;
library Project1;
uses
// Forms, // 我们自己生成窗体
Unit1 in 'Unit1.pas' {Form1};
//告诉编译器,我们输出的函数
exports
ListMove;
{$R *.RES}
begin
// Application.Initialize;
// Application.CreateForm(TForm1, Form1);
// Application.Run;
end.
步骤4 编译工程文件生成DLL文件
步骤5 在需要该窗体的其他应用程序中重用该窗体
implementation
{$R *.DFM}
//调用DLL窗体文件声明
function ListMove(var l1,l2:Integer):wordbool;far;external 'Project1.dll'
{点击确定,调用DLL文件}
procedure TForm1.Button1Click(Sender: TObject);
var
l1,l2:Integer; //传地址过去,直接修改l1,l2
begin
if ListMove(l1,l2) then
begin
Edit1.Text:=IntToStr(l1);
Edit2.Text:=IntToStr(l2);
end;
end;
通过这种方式,你可以有效地在多个 Delphi 应用程序之间重用窗体代码。
完整代码
在 。
强制卸载工具
最近安装Adobe时,它顺带安装了一个McAFee,结果删的时候,只显示一部分,无法点击卸载按钮。
去官网找客户服务,他推荐了一个
。很不错,能强制卸载,顺带清理其所有文件。
工具界面很整洁,使用简单方便。
版权声明:本文标题:Delphi5利用DLL实现窗体的重用_delphi dll 窗体 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1773816089a3566038.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论