我想编制一个小型广告表格,让我轻松地将其应用到我的任何其他项目中。 广告表单应该出现在我的真实项目/应用程序开始之前。
必须满足一些要求:
到目前为止我的进展是:
到目前为止,这就是我所拥有的:
项目来源:
program MyTestProgram;
uses
Vcl.Forms,
Windows,
uMainWindow in 'uMainWindow.pas' {Form1},
uEmptyForm in '..\AdProject\uEmptyForm.pas' {AdEmptyMainForm},
uWelcomeScreen in '..\AdProject\uWelcomeScreen.pas' {WelcomeScreen}; // shouldn't be here
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Run;
LoadAdWindow('Title of my app', uMainWindow.TForm1, uMainWindow.Form1);
end.
EmptyForm单位:
unit uEmptyForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TAdEmptyMainForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
AdEmptyMainForm: TAdEmptyMainForm;
procedure LoadAdWindow (Appname: string; InstanceClass: TComponentClass; var Reference);
implementation
{$R *.dfm}
uses
uWelcomeScreen; // Has to be added to the project, otherwise it doesn't detect the unit in the same path as this unit
procedure LoadAdWindow (Appname: string; InstanceClass: TComponentClass; var Reference);
begin
Application.MainFormOnTaskbar := True;
Application.ShowMainForm := False;
Application.Title := Appname;
Application.CreateForm(TAdEmptyMainForm, AdEmptyMainForm);
with uWelcomeScreen.TWelcomeScreen.Create(Application.MainForm) do
begin
Caption := Appname;
if ShowModal <> 1337 then ExitProcess(0);
Free;
end;
Application.CreateForm(InstanceClass, Reference);
end;
end.
欢迎屏幕成功后,应用程序关闭。 这甚至是正确的方式吗? 任何帮助表示赞赏!
答案 0 :(得分:4)
您可以轻松创建并显示广告表单,然后创建并显示主表单,如下所示:
connmanctl> tether wifi disable
connmanctl> enable wifi
connmanctl> scan wifi
connmanctl> services // will list the detected 2.4 GHz WAP
connmanctl> agent on
connmanctl> connect wifi_*_managed_psk // specify WAP to connect
connmanctl> quit
请注意,项目的主窗体是使用var
FAdFrm : TAdFrm;
begin
FAdFrm := TAdFrm.Create(nil);
if FAdFrm.ShowModal = mrOK then
begin
FAdFrm.Free;
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TMainFrm, MainFrm);
Application.Run;
end
else
FAdFrm.Free;
方法
答案 1 :(得分:4)
Application.MainForm
是通过Application.CreateForm()
对TForm
派生类的第一次调用建立的。如果未分配Application.Run()
,Application.MainForm
会立即退出。
要做你正在尝试的事情,你应该更像下面这样做。您不需要空白的MainForm,只需在创建真实的MainForm之前创建并显示广告窗口。只需要更改项目主要来源:
program MyTestProgram;
uses
Vcl.Forms,
Windows,
uMainWindow in 'uMainWindow.pas' {Form1},
uWelcomeScreen in '..\AdProject\uWelcomeScreen.pas' {WelcomeScreen};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Title := 'Title of my app';
with TWelcomeScreen.Create(Application) do
try
Caption := Application.Title;
if ShowModal <> 1337 then
Exit;
finally
Free;
end;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
答案 2 :(得分:1)
另一种方法是在MainForm的创建活动中创建广告表单。我在自己的项目中这样做。
procedure TMainForm.FormCreate(Sender: TObject);
begin
AdvForm := TAdvForm.Create(Self);
Try
AdvForm.ShowModal;
finally
AdvForm.Free;
end;
end;