1
votes

maybe this is a lame question, but nevertheless...
I asked some questions about the plugins in delphi. What is the better way dll, bpl, OCX, scripting engine...
I dont feel like to distribute all *.bpls, and all its dependencies...
All I need is a *.dll which contains a TForm. And that Form should be placed into the host application. There is no direct support for this in delphi (very sad situation). Some workarounds exists, but there are problems with tab key etc...
So non workaround is perfect.
But maybe there is an another possibility. Inject dll code directly into the host *.exe. So the *.exe will think that injected code his its own... And lot of problems (e.g. with tab key in form) should be gone. Is it possible? isn't it a dirty hack, e.g. 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. First is an error "cannot assign TFont to a TFont", but there is a some workaround for this.
Second is that host application take whole embeded form as one component, so you cannot use a tab key. (After pressing tab, focus will completly jump out of embeded form). 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.
But as I said before, I dont know anything about injecting, just a (maybe) crazy idea ;)

1
It's no problem whatsoever to create a DLL which shows VCL forms that behave perfectly. The standard example I would use is an Office COM add-in. I have one of those, written using Add-in Express. It works a treat. Your problem lies elsewhere and you most certainly do need to inject anything anywhere!David Heffernan
This question is too open, it is better if you address specific problems in your question. For example, what's resolved by making the exe think the injected code is it's own code? AFAIK, there's no generalized tab problem using forms coming from dll's in a Delphi application and I really can't see how this can be solved with this approach, since the problem may be global objects the form contained in the DLL will be different from the global objects of the host application. In your words, the problem is what the dll code thinks about itself, and not what the exe thinks about the dll.jachguate

1 Answers

1
votes

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. On the other side create a Delphi app and add the following code to call the 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.