通过DLL在Inno Setup中显示使用Delphi创建的FMX或VCL表单?

时间:2018-01-19 11:39:38

标签: delphi inno-setup firemonkey vcl delphi-10.2-tokyo

我正在尝试使用dll在Inno Setup中显示FMX表单。我创建了一个DLL并将表单添加到DLL.dll。 这是来自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.

这里是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;

设置编译但未显示表单并退出而不显示任何错误。

它与cmd,vcl应用程序工作正常,但与inno不是。 我使用以下代码在cmd,vcl apps:

中显示来自dll的表单
procedure ShowForm; stdcall; external 'DLL.dll';
...
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Free;
ShowForm;
end;

1 个答案:

答案 0 :(得分:2)

除非绝对必要,否则您不应该尝试从Inno Setup中调用外部表单。 Inno是一个非常强大的设置工具,允许您使用它自己的脚本创建自定义页面(表单)。我真的很鼓励你仔细阅读Inno关于自定义页面的帮助,这个过程记录得很清楚。话虽如此,这里有一段可能让你入门的代码:

[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;

你声明一个TWizardPage类型的全局变量,实现你自己的一个过程来呈现表单(如:CreateCustomUserInfoPage),在这个过程中你将内置函数CreateCustomPage返回的值赋给TWizardPage全局变量,添加表单中的一些组件,稍后您将在InitializeWizard内置过程中调用此过程。

这只是一个很小的实际例子,根据您的需求变得更加复杂。但软件的帮助应该涵盖几乎任何东西。至于DLL,我只留下那些没有Inno Setup Pascal Scripting功能所涵盖的复杂工作。希望它有所帮助。

相关问题