欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > Delphi5利用DLL实现窗体的重用

Delphi5利用DLL实现窗体的重用

2024/10/25 15:28:53 来源:https://blog.csdn.net/weixin_52116519/article/details/127908753  浏览:    关键词:Delphi5利用DLL实现窗体的重用

文章目录

    • 效果图
    • 参考
    • 利用DLL实现窗体的重用
      • 步骤1 设计出理想窗体
      • 步骤2 编写一个用户输出的函数或过程,在其中对窗体进行创建使它实例化
      • 步骤3 对工程文件进行相应的修改以适应DLL格式的需要
      • 步骤4 编译工程文件生成DLL文件
      • 步骤5 在需要该窗体的其他应用程序中重用该窗体
    • 完整代码
    • 强制卸载工具

效果图

在这里插入图片描述

参考

利用DLL实现窗体的重用

在 Delphi 5 中,通过 DLL(动态链接库)实现窗体的重用是一种高级技术,它允许你在多个应用程序之间共享窗体代码。这通常用于减少代码冗余,提高开发效率,并允许模块化设计。

步骤1 设计出理想窗体

像平时一样设计一个窗体,调试运行成功。

在这里插入图片描述

{将左边选中的移到右边}
procedure TForm1.Button1Click(Sender: TObject);
vari: Integer;
beginfor i:=ListBox1.Items.Count-1 downto 0 dobeginif ListBox1.Selected[i] thenbeginListBox2.Items.Add(ListBox1.Items[i]);     //加到另外框ListBox1.Items.Delete(i);      //删除选中end;end;
end;{将左边全部移到右边}
procedure TForm1.Button2Click(Sender: TObject);
vari: 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;
beginfor i:=ListBox2.Items.Count-1 downto 0 dobeginif ListBox2.Selected[i] thenbeginListBox1.Items.Add(ListBox2.Items[i]);     //加到另外框ListBox2.Items.Delete(i);      //删除listbox中选中的end;end;
end;{将右边全部移到左边}
procedure TForm1.Button4Click(Sender: TObject);
vari: Integer;
beginfor i := 0 to ListBox2.Items.Count - 1 dobeginListBox1.Items.Add(ListBox2.Items[i]);end;ListBox2.Items.Clear;
end;{点击确定}
procedure TForm1.Button5Click(Sender: TObject);
beginmodalresult:=mrOK;
end;{点击取消}
procedure TForm1.Button6Click(Sender: TObject);
beginmodalresult:=mrCancel;
end;

步骤2 编写一个用户输出的函数或过程,在其中对窗体进行创建使它实例化

varForm1: TForm1;function ListMove(var l1,l2:Integer):wordbool;export;   //让外部调用{返回选中了几门课程}
function ListMove(var l1,l2:Integer):wordbool;
beginresult:=False;Form1:=TForm1.create(Application); //调用这个DLL时,创建窗体(实例化)tryif Form1.showmodal=mrOk then    //点击确定with Form1 dobeginl1:=listbox1.items.count;l2:=listbox2.items.count;result:=True;end;finallyForm1.free;end;
end;

步骤3 对工程文件进行相应的修改以适应DLL格式的需要

//program Project1;
library Project1;uses
//  Forms,   // 我们自己生成窗体Unit1 in 'Unit1.pas' {Form1};//告诉编译器,我们输出的函数
exportsListMove;
{$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);
varl1,l2:Integer;      //传地址过去,直接修改l1,l2
beginif ListMove(l1,l2) thenbeginEdit1.Text:=IntToStr(l1);Edit2.Text:=IntToStr(l2);end;
end;

通过这种方式,你可以有效地在多个 Delphi 应用程序之间重用窗体代码。

完整代码

在这。

在这里插入图片描述

强制卸载工具

最近安装Adobe时,它顺带安装了一个McAFee,结果删的时候,只显示一部分,无法点击卸载按钮。

在这里插入图片描述

去官网找客户服务,他推荐了一个工具。很不错,能强制卸载,顺带清理其所有文件。
在这里插入图片描述

工具界面很整洁,使用简单方便。

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com