Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Outsource a form in a separate DLL



Permlink Replies: 4 - Last Post: Jul 18, 2017 4:49 PM Last Post By: Alexandre Machado
Jörg Heim

Posts: 71
Registered: 7/24/16
Outsource a form in a separate DLL
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 3, 2017 7:43 AM
Hi,

we want to outsource some (SA) program parts in an extra DLL.
How can we create and show a new form in this DLL?
(I think we have to pass an handle or Parent)

Kind regards
Jörg Heim

Posts: 71
Registered: 7/24/16
Re: Outsource a form in a separate DLL
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2017 12:38 AM   in response to: Jörg Heim in response to: Jörg Heim
Ok,

sounds like a silly question, but the aim is not stupid.
It's common to outsource parts of windows programs (even forms) in dlls.

Forms in a normal dll will be compiled as windows forms.
But we need the result as html & javascript for the browser.

Questions:

1.) Is there a technique existing in intraweb to do this?

2.) Would it be possible for Atozed to invent this?
Jörg Heim

Posts: 71
Registered: 7/24/16
Re: Outsource a form in a separate DLL
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 12, 2017 5:23 AM   in response to: Jörg Heim in response to: Jörg Heim
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// we tried to call a new form out of a DLL, likely as we
// called other IW-forms out of internal units -> FAILED
//
// so our question is: which parameters or settings are
// necessary to call an IW-form out of an DLL ?
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

// calling procedure in UMain.pas:

procedure TIWForm1.IWButton3Click(Sender: TObject);
begin
try
FhDll := LoadLibrary(PChar('IW_sub_DLL.dll'));
if (FhDll = 0) then
raise Exception.Create('DLL not found !');
@FpShowDLL := GetProcAddress(FhDll, PChar('ShowForDLL'));
if (not Assigned(FpShowDLL)) then
raise Exception.Create('func. not found !');

FpShowDLL(WebApplication); // hWin ?? WebApplication ??

FreeLibrary(FhDll);
FhDll := 0;
@FpShowDLL := nil;

except
IWEdit1.Text := 'DLL-Call-ERROR (show)';
end;

end;

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// called procedure[s] in referenced IW_sub_DLL:
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
library IW_sub_DLL;

uses
IWRtlFix, IW.Export, SysUtils, Forms, Classes, IWApplication,
UnitExt in 'UnitExt.pas' {IWFormE: TIWAppForm},
Winapi.Windows, Winapi.Messages, System.Variants;

//ServerController in 'ServerController.pas' {IWServerController: TIWServerControllerBase},
//UserSessionUnit in 'UserSessionUnit.pas' {IWUserSession: TIWUserSessionBase};

{$R *.RES}

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// this easy DLL-function is running well
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function GetResp (sInputP: PChar) : PChar; stdcall;
begin
Result := PChar(Uppercase(sInputP));
end;

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// BUT THIS ONE is called and FAILS with "ACCESS VIOLATION"
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
procedure ShowForDLL(appW : TIWApplication); stdcall; // ? hWin : HWND ?
var
xFrmE: TIWFormE;

begin
//RegisterClasses([TIWFormE]); // independant whether used or not
//xFrmE := TIWFormE.CreateParented(hWin);
//xFrmE := TIWFormE.CreateNew(appW); // ?? nil ?? appW ??
xFrmE := TIWFormE.Create(appW); // "PoC", Point of Crash, access viol.;
// try
xFrmE.Show; // "PoC" if created by CreateNew();
// finally
// Form.Free;
// end;

end;

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// the call of DLL-funcs with export etc. is well known
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
exports ShowForDLL;

exports GetResp;

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// (we also tried with "IW Library"-settings - same result)
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//initialization // NOT HERE ?!
// RegisterClasses([TIWFormE]);

begin

end.
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Outsource a form in a separate DLL
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2017 4:42 PM   in response to: Jörg Heim in response to: Jörg Heim
Jörg Heim wrote:
Hi,

we want to outsource some (SA) program parts in an extra DLL.
How can we create and show a new form in this DLL?
(I think we have to pass an handle or Parent)

Kind regards

Hi Jörg,

Actually this is not a limitation imposed by IntraWeb, but by Delphi itself (and how the memory management works).

It is not impossible, but using objects like TIWForm (or a TForm) is very challenging across DLL boundaries. You have similar issues if you try to put MDI forms inside a DLL and use it with your Desktop Delphi application (again, it is not impossible, but you have to use several different hacks and the end result is not 100%).

Have you considered packages? That's the best option if you need to do that.

I don't recommend it either, because I think it increases project complexity, but it works.
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Outsource a form in a separate DLL
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2017 4:49 PM   in response to: Jörg Heim in response to: Jörg Heim
Adding some more detail to it, using an analogy with Delphi desktop applications:

- The biggest problem here are the global objects like ServerController and WebApplication (in a desktop application you have the same issue with objects like TScreen and TApplication). Various components of a IWApplication rely on those objects. However, if you have a EXE and a DLL, they don't share those objects, unless you create a mechanism to do so. Again, I think it might be possible (if the DLL and EXE are built using the exact same Delphi compiler), but you will add a huge amount of complexity to your application, for very little benefit.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02