简体   繁体   English

使用注入的dll代码作为包含TForm的delphi * .dll插件

[英]Use injected dll code as delphi *.dll plugin which contains TForm

maybe this is a lame question, but nevertheless... 也许这是一个la脚的问题,但是...
I asked some questions about the plugins in delphi. 我问了一些有关delphi插件的问题。 What is the better way dll, bpl, OCX, scripting engine... dll,bpl,OCX,脚本引擎的更好方法是什么?
I dont feel like to distribute all *.bpls, and all its dependencies... 我不想分发所有* .bpls及其所有依赖项...
All I need is a *.dll which contains a TForm. 我只需要一个* .dll,其中包含一个TForm。 And that Form should be placed into the host application. 并且该表格应放置在主机应用程序中。 There is no direct support for this in delphi (very sad situation). 在delphi中没有直接的支持(非常可悲的情况)。 Some workarounds exists, but there are problems with tab key etc... 存在一些解决方法,但是Tab键等存在问题。
So non workaround is perfect. 因此,非解决方法是完美的。
But maybe there is an another possibility. 但是也许还有另一种可能性。 Inject dll code directly into the host *.exe. 直接将dll代码注入主机* .exe。 So the *.exe will think that injected code his its own... And lot of problems (eg with tab key in form) should be gone. 因此* .exe会认为自己注入的代码是自己的...并且应该解决很多问题(例如,使用制表符的形式)。 Is it possible? 可能吗? isn't it a dirty hack, eg is that technique "programatically" legal? 这不是一个肮脏的技巧吗?例如,该技术“以编程方式”合法吗?
(I have no experience with code injecting, and maybe it doesn't make sence what I'm saying here ;) (我没有代码注入的经验,也许它没有引起我在这里说的话;)

best regards 最好的祝福
Peter 彼得

[edited] [编辑]
To clarify some things... When we put a TForm in dll and than we try this form embed to the host *.exe application, a lot of problems arise. 为了澄清一些事情...当我们将TForm放入dll中,然后尝试将此表单嵌入到主机* .exe应用程序中时,会出现很多问题。 First is an error "cannot assign TFont to a TFont", but there is a some workaround for this. 首先是一个错误“无法将TFont分配给TFont”,但是有一些解决方法。
Second is that host application take whole embeded form as one component, so you cannot use a tab key. 其次,主机应用程序采用整体嵌入形式作为一个组件,因此您不能使用Tab键。 (After pressing tab, focus will completly jump out of embeded form). (按Tab后,焦点将完全跳出嵌入形式)。 Also we have some workaround for this, but it is far away from perfect... 我们对此也有一些解决方法,但是离完美还很遥远...
So I had an idea, if we inject some code to the host, maybe host will be think that emebeded form his is own code, so tab key will be working. 所以我有一个主意,如果我们向主机注入一些代码,也许主机会认为他的代码是自己的代码,所以Tab键会起作用。
But as I said before, I dont know anything about injecting, just a (maybe) crazy idea ;) 但是正如我之前说的,我对注射一无所知,只是一个(也许)疯狂的主意;)

This is perfectly possible without recourse to any of the hacks you describe. 这完全是可能的,无需求助于您描述的任何技巧。 For example: 例如:

library FormDLL;

uses
  Windows,
  Forms,
  uMyForm in 'uMyForm.pas' {MyForm};

procedure ShowForm(MainFormHandle: HWND); stdcall;
begin
  Application.Handle := MainFormHandle;
  with TMyForm.Create(nil) do begin
    ShowModal;
    Free;
  end;
end;

exports
  ShowForm;

begin
end.

You can put pretty much anything you like in TMyForm . 您可以在TMyForm放入任何您喜欢的TMyForm On the other side create a Delphi app and add the following code to call the DLL: 在另一方面,创建一个Delphi应用程序并添加以下代码以调用DLL:

procedure ShowForm(MainFormHandle: HWND); stdcall; external 'FormDLL.dll';

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ShowForm(Handle);
end;

This behaves just perfectly. 这表现得很完美。

So, I'm afraid it's not obvious what your problem is. 因此,恐怕您的问题并不明显。 If you can supply more details, then please do so. 如果您可以提供更多详细信息,请这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM