如何使用现成的BPL?

confucius 2007-09-17 02:51:06
有一用Delphi做成的现成系统,我手头只有可执行程序,没有源代码,也没有文档,该系统有很多的BPL文件,我现在需要调用一下该系统的功能,我如何去着手?怎样分析这些BPL文件,还有如何调用里面的函数,类啊什么的??大家帮忙提供一下思路。。。。。
...全文
180 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
13193887977 2007-09-19
  • 打赏
  • 举报
回复
版本要是不一样,也不行啊
WuChenCan 2007-09-18
  • 打赏
  • 举报
回复
只有可执行程序难呀,帮顶一下,,
confucius 2007-09-18
  • 打赏
  • 举报
回复
谢谢,朋友们还有什么好建议吗?
hongqi162 2007-09-17
  • 打赏
  • 举报
回复

主要是这部分

Dynamically loaded BPLs

BPLs are just as simple. Well almost.

We dynamically load the package by using the LoadPackage function.

function LoadPackage(const Name: string): HMODULE;

We create TPersistentClass of the class we wish to instantiate by using the GetClass function.

function GetClass(const AClassName: string):
TPersistentClass;

Instantiate an object of the loaded class and use it.

And when we are done, unload the package using the UnloadPackage procedure.

procedure UnloadPackage(Module: HMODULE);

Let us go back to our example and make a few changes:

1. Select "Project1.exe" from the project manager.
2. Right-click and select "Options..."
3. Select the "Packages" tab.
4. Remove "Package1" from the "Runtime packages" edit-box section and OK the options.
5. On Delphi's toolbar, click on the "Remove file from project" button.
6. Select "Unit2 | Form2" from the list and then "OK."
7. Now go to the "Unit1.pas" source and remove Unit2 from its uses clause. (These steps are required to remove any link to Unit2 and the package we wish to load dynamically.)
8. Go to the source of Button1's OnClick event.
9. Add two variables of type HModule and TPersistentClass.

var
PackageModule: HModule;
AClass: TPersistentClass;

10. Load the package Package1 by using the LoadPackage function.

PackageModule := LoadPackage('Package1.bpl');

11. Check that the Package Module is not 0 (zero).
12. Create a persistent class using the GetClass function, passing it the name of the form within the package as its parameter:

AClass := GetClass('TForm2');

13. If the persistent class is not nil, create and use an instance of the class just a before.

with TComponentClass(AClass).Create(Application)
as TCustomForm do
begin
ShowModal;
Free;
end;

14. Finally, unload the package using the UnloadPackage procedure:

UnloadPackage(PackageModule);

15. Save the project.

Here is the complete listing of the OnClick event:

procedure TForm1.Button1Click(Sender: TObject);
var
PackageModule: HModule;
AClass: TPersistentClass;
begin
PackageModule := LoadPackage('Package1.bpl');
if PackageModule <> 0 then
begin
AClass := GetClass('TForm2');

if AClass <> nil then
with TComponentClass(AClass).Create(Application)
as TCustomForm do
begin
ShowModal;
Free;
end;

UnloadPackage(PackageModule);
end;
end;

Unfortunately that's not the end of it.

The problem is that the GetClass function requires the class to be registered before the function can find it. Usually form classes and component classes that are referenced in a form declaration (instance variables) are automatically registered when the form is loaded. But the form isn't loaded yet. So where should we register the class? The answer: in the package. Each unit in the package is initialized when the package is loaded and finalized when the package is unloaded.

Let's return to our example and make a few changes:

1. Double-click on "Package1.bpl" in the project manager; this will activate the package editor.
2. Click on the + symbol next to "Unit2" in the "Contains" section. This will expand the unit tree.
3. Double-click on "Unit2.pas" to activate the unit's source code.
4. Scroll down to the end of the file and add an initialization section.
5. Register the form's class using the RegisterClass procedure:

RegisterClass(TForm2);

6. Add a finalization section.
7. Un-register the form's class using the UnRegisterClass procedure:

UnRegisterClass(TForm2);

8. Finally, save and compile the package.

Now we can safely run the "Project1" application - it will function just as before, but with the added benefit of being able to load the package when you want to.
Finally

Make sure you compile any project that uses packages (static or dynamic) with runtime packages turned on: "Project | Options | Packages | Build with runtime packages."

You must be careful that when you unload a package you destroy any objects using those classes and un-register any classes that were registered.

This procedure may help:

procedure DoUnloadPackage(Module: HModule);
var
i: Integer;
M: TMemoryBasicInformation;
begin
{ Make sure there aren't any instances of any
of the classes from Module instantiated, if
so then free them. (This assumes that the
classes are owned by the application) }

for i := Application.ComponentCount - 1 downto 0 do
begin
VirtualQuery(
GetClass(Application.Components[i].ClassName),
M, SizeOf(M));
if (Module = 0) or
(HMODULE(M.AllocationBase) = Module) then
Application.Components[i].Free;
end;
UnRegisterModuleClasses(Module);
UnLoadPackage(Module);
end;

An application requires "knowledge" of the registered class names prior to loading the package. One way to improve this would be to create a registration mechanism to inform the application of all the class names registered by the package.
hongqi162 2007-09-17
  • 打赏
  • 举报
回复
http://dn.codegear.com/article/27178
1.windows的path路径中增加D7的路径 在启用delphi7时,要能加载dclIndyCore70.bpl这个文件 如果是自动安装,这个文件会拷到C:\windows\system32\dclIndyCore70.bpl,所以不用改path 2.delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 添加indey10\D7 因为这个目录下有bpl和dcu文件 3.删除delphi7目录Bin下的indy*.BPL文件,这是官方旧版本的文件,放心删除。 4.删除delphi7目录下的 Id*.DCU文件,一般都是在lib目录里。 5.打开indy10\lib目录,安装DPK包顺序如下: (1)编译 System\IndySystem70.dpk (只需要compile) (这个不是设计包,不需要install) (2)编译 Core\IndyCore70.dpk (只需要compile) 编译安装Core\dclIndyCore70.dpk (设计包,先complie后install) (3)编译 Protocols\IndyProtocols70.dpk (只需要compile) 编译安装Protocols\dclIndyProtocols70.dpk (设计包,先complie后install) 6.完成 【第二次手工安装】 第一步: indy10\D7目录下的5个文件 复制到 D:\Delphi7_Ent\Projects\Bpl IndySystem70.bpl IndyCore70.bpl IndyProtocols70.bpl dclIndyCore70.bpl dclIndyProtocols70.bpl 第二步: 打开delphi7菜单 Component/install packpages/ add dclIndyCore70.bpl 再add dclIndyProtocols70.bpl 第三步 打开delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 完成!更简单。前提是要有现成bpl的文件,如果没有bpl文件,还得需要dpk编译
1.windows的path路径中增加D7的路径 在启用delphi7时,要能加载dclIndyCore70.bpl这个文件 如果是自动安装,这个文件会拷到C:\windows\system32\dclIndyCore70.bpl,所以不用改path 2.delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 添加indey10\D7 因为这个目录下有bpl和dcu文件 3.删除delphi7目录Bin下的indy*.BPL文件,这是官方旧版本的文件,放心删除。 4.删除delphi7目录下的 Id*.DCU文件,一般都是在lib目录里。 5.打开indy10\lib目录,安装DPK包顺序如下: (1)编译 System\IndySystem70.dpk (只需要compile) (这个不是设计包,不需要install) (2)编译 Core\IndyCore70.dpk (只需要compile) 编译安装Core\dclIndyCore70.dpk (设计包,先complie后install) (3)编译 Protocols\IndyProtocols70.dpk (只需要compile) 编译安装Protocols\dclIndyProtocols70.dpk (设计包,先complie后install) 6.完成 【第二次手工安装】 第一步: indy10\D7目录下的5个文件 复制到 D:\Delphi7_Ent\Projects\Bpl IndySystem70.bpl IndyCore70.bpl IndyProtocols70.bpl dclIndyCore70.bpl dclIndyProtocols70.bpl 第二步: 打开delphi7菜单 Component/install packpages/ add dclIndyCore70.bpl 再add dclIndyProtocols70.bpl 第三步 打开delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 完成!更简单。前提是要有现成bpl的文件,如果没有bpl文件,还得需要dpk编译
indy10.2.3 full 完全安装版 D7~2010 版本:indy10.2.3 经delphi7下的安装成功,delphi11和delphi6的安装没有试用 【自动安装】 Lib\Fulld7.bat 双击运行即可。 自动会把bpl文件拷到C:\windows\system32 重新打开delphi7会自动加载 dclIndyCore70.bpl dclIndyProtocols70.bpl 【手工安装】 1.windows的path路径中增加D7的路径 在启用delphi7时,要能加载dclIndyCore70.bpl这个文件 如果是自动安装,这个文件会拷到C:\windows\system32\dclIndyCore70.bpl,所以不用改path 2.delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 添加indey10\D7 因为这个目录下有bpl和dcu文件 3.删除delphi7目录Bin下的indy*.BPL文件,这是官方旧版本的文件,放心删除。 4.删除delphi7目录下的 Id*.DCU文件,一般都是在lib目录里。 5.打开indy10\lib目录,安装DPK包顺序如下: (1)编译 System\IndySystem70.dpk (只需要compile) (这个不是设计包,不需要install) (2)编译 Core\IndyCore70.dpk (只需要compile) 编译安装Core\dclIndyCore70.dpk (设计包,先complie后install) (3)编译 Protocols\IndyProtocols70.dpk (只需要compile) 编译安装Protocols\dclIndyProtocols70.dpk (设计包,先complie后install) 6.完成 【第二次手工安装】 第一步: indy10\D7目录下的5个文件 复制到delphiD:\Delphi7_Ent\Projects\Bpl IndySystem70.bpl IndyCore70.bpl IndyProtocols70.bpl dclIndyCore70.bpl dclIndyProtocols70.bpl 第二步: 打开delphi7菜单 Component/install packpages/ add dclIndyCore70.bpl 再 add dclIndyProtocols70.bpl 第三步 打开delphi7菜单中Library路径中 添加indy10\LIB路径下的System、Core、Protocols下的三个目录 完成!更简单。前提是要有现成bpl的文件,如果没有bpl文件,还得需要dpk编译
FinalBuilder解决的是任务流的问题。就像我们以前的DOS系统的大部分程序一样,没有界面交互部分,一次输入,直接返回最终处理结果。这点和我们的自动化目标不谋而合。   在FinalBuilder中,最本质的就是一次任务的执行。任务的执行包括两部分:执行环境+执行数据。执行环境往往包括Windows系统自带的一些程序,包括Copy,XCopy等等Shell命令。也有系统中已经安装的程序,如Delphi、VC、SVN等等。而执行数据,则是指我们的输入了!由于我们要达到在执行中不存在界面交互,那么就必然要求我们将所有需要交互的信息一次性地输入。于此同时,我们的环境程序,也必须同时支持此种模式(一般这种模式,称之为命令行模式)。   对于使用FinalBuilder的人来讲,就有必要了解相关程序的命令行调用方式。这样有助于我们使用和编写任务。如果是我们自己研发一个程序,那么因为要使用到FinalBuilder中来,也有必要支持命令行模式。   在FinalBuilder中,最主要的还是顺序流程,当然它也支持条件(if)、分支(case)、循环(loop)。最新的版本还有多线程协同。不过在使用初期,主要还是以顺序流程为主了。   最关键最有用的就是Run DOS Command和Execute Programe两个Action(任务)了。有了这两个,你几乎可以完成任何事情。当然了FinalBuilder还提供了很多现成的控件,使得你可以通过配置(而不是命令行)来编写任务。这大大降低了使用难度。不过,不可避免的会有一些需求需要我们自己编写命令行,因此着两个Action必须掌握。   FinalBuilder的自动执行,是使用Windows的计划任务来完成的。在其菜单中有生成计划任务的功能。顺便说一句,FinalBuilder也一样支持命令行模式,因此多个FinalBuilder之间可以互相调用。这对我们的自动化非常有利。 //////////////////////////////////////////// 含license,和patch文件,和英文的操作手册; 先运行patch,再导入license文件即可解除限制; 已知问题 vista系统下patch文件执行有问题,请在xp下安装并完成破解,后将破解后的FBCoreAPI.bpl覆盖原来的那个文件后,再导入压缩包中的FinalBuilder6.license文件,就可以了。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧