0

I am trying to show a FMX form in Inno Setup using an dll. i created a DLL and added the form to the DLL.dll. here is the code from the dll:

library DLL;

uses
  System.SysUtils,
  System.Classes,
  Winapi.Windows, Winapi.Messages, System.Variants,
  DLLForm in 'DLLForm.pas' {Form2};

{$R *.res}
procedure ShowForm; stdcall;
begin
  Form2:=TForm2.Create(nil);
  Form2.ShowModal;
  Form2.Free; //Added this line.
  end;

Exports ShowForm;
end.

and here it is the code for inno:

[Setup]
AppName=Windows
AppPublisher=Stack
AppVersion=1.0.0.0
DefaultDirName={pf}\FMXForm

[Files]
Source: Include\DLL.dll; DestDir: {tmp} Flags: dontcopy;

[code]
procedure Show;
external 'ShowForm@Files:DLL.dll stdcall delayload';

procedure InitializeWizard();
begin
  Show;
end;

Setup Compiles but did not showing the form and exits without showing any errors.

It is working fine with cmd,vcl apps but with inno it is not. I used following code to show the form from dll in cmd,vcl apps :

procedure ShowForm; stdcall; external 'DLL.dll';
...
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Free;
ShowForm;
end;
bear
  • 43
  • 6
  • 1
    This is utter masochism. Make a VCL form for pity's sake! – David Heffernan Jan 19 '18 at 11:43
  • it is working fine with `cmd` app and with `vcl` app created in Delphi but with `inno` it's not working. I Tried to create an `vcl` form with same method above but it is not working. – bear Jan 19 '18 at 12:00
  • So you get the same problem with VCL as with FMX? – Martin Prikryl Jan 19 '18 at 12:12
  • Yes, but i think it is problem with `inno` procedure calling code because it is working fine with `cmd` ,`VCL` apps. – bear Jan 19 '18 at 12:23
  • Then you should modify your question to ask about VCL, as you will get much wider audience. + *"it is working fine with cmd ,VCL apps"* - in those apps, do you call the DLL? Show us how. – Martin Prikryl Jan 19 '18 at 12:31
  • Yes it is working fine in those apps and i added the procedure that calls the dll's procedure in main question/post. – bear Jan 19 '18 at 13:12
  • This is incomplete. We don't have the form code. Perhaps the issue lies there. Also, who wants an install program that shows other windows. That's nasty UI. And if you simply must, at least set the window popup parent. – David Heffernan Jan 19 '18 at 14:08
  • So is your procedure called at all? Did you try doing something simple there, like writing a message to a file (removing all VCL code and references)? – Martin Prikryl Jan 19 '18 at 14:18
  • @DavidHeffernan There is nothing in the Form. it is just blank form with a label on it. – bear Jan 19 '18 at 17:55
  • @MartinPrikryl I have tried with simple `ShowMessage` dll which includes `VCL.Dialogs` and same it doesn't shows the message either. – bear Jan 19 '18 at 17:58
  • That's not really an answer to my question. – Martin Prikryl Jan 19 '18 at 18:46
  • Have you tried to remove "delayload" option or "InitializeSetup" procedure? _During Setup, a special 'files:' prefix may also be used to instruct Setup to automatically extract one or more DLLs from the [Files] section before loading the first DLL._ – kot-da-vinci Jan 20 '18 at 11:42
  • it is weird but it worked somehow with the same code. still can't figure out the error. but still sometime it didn't compiles and gives errors. Sorry for too late reply people. – bear Jan 28 '18 at 12:12

1 Answers1

2

You shouldn't really try to call an external Form from within Inno Setup unless absolutely necessary. Inno is a very powerful setup tool that allows you to create custom Pages (Forms) using it's own script. I really encourage you to read very thoroughly Inno's help about custom pages, the process is very well documented. Having said that, here's a piece of code that might get you started:

[Code]

var
  UserInfoPage: TWizardPage;

procedure CreateCustomUserInfoPage;
begin
  UserInfoPage := CreateCustomPage(wpWelcome, 'User information', 'Please insert user information.');

  { First Name Field }

  FNLabel := TLabel.Create(UserInfoPage);
  with FNLabel do
  begin
    Caption := 'First Name:';
    Parent := UserInfoPage.Surface;
  end;

  FNEdit := TEdit.Create(UserInfoPage);
  with FNEdit do
  begin
    Top := FNLabel.Top + FNLabel.Height + 4;
    Width := (UserInfoPage.SurfaceWidth div 2) - 8;
    Parent := UserInfoPage.Surface;
    OnKeyPress := @FNEditOnKeyPress; // Just an event handler. If assigned, it should be implemented in the [code] section.
  end;

  { ...The rest of the fileds here... }

end;

procedure InitializeWizard;
begin
  CreateCustomUserInfoPage;
end;

You declare a global variable of type TWizardPage, implement a procedure of your own to render the form (like: CreateCustomUserInfoPage), inside this procedure you assign the value returned by the built-in function CreateCustomPage to the TWizardPage global variable, add some components to the form, and later on you call this procedure from within the InitializeWizard built-in proc.

This is just a small practical example, it gets more complex depending on what your needs are. But the software's help should cover pretty much anything. As for the DLLs, I only leave those for really intricate work that is not covered by the Inno Setup Pascal Scripting functionality. Hope it helped.

Alex_89
  • 371
  • 5
  • 15
  • Thanks for the answer but this not what i need. – bear Jan 28 '18 at 12:13
  • Ok, so what exactly do you need? Maybe we can still help. Please, elaborate a little bit more. – Alex_89 Jan 28 '18 at 18:08
  • It is Weird but now it's working like charm for me. The Dll is working with the code i wrote above but with exit error where it hangs a bit. – bear Feb 14 '18 at 09:39