Recent

Author Topic: Failed to create win32 control, error 1407: cannot find window class  (Read 8780 times)

talorigomat

  • Jr. Member
  • **
  • Posts: 96
I've converted the example delphi project below (and also typed it in by hand) however ater compiling it gives the above error and states it is "in file win32controls.pp at line 259."  The idea of the program is to display a login in form before the main application form is created and displayed. The example is taken from the follow site:

http://delphi.about.com/od/windowsshellapi/a/password_login.htm

Is there a way to do this in Lazarus?

program PasswordApp;

{$MODE Delphi}

uses
  Forms, Interfaces, LCLType,
  main in 'main.pas' {MainForm},
  login in 'login.pas' {LoginForm};

{$R *.res}

begin
  if TLoginForm.Execute then
  begin
    Application.Initialize;
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
  end
  else
  begin
    Application.MessageBox('You are not authorized to use the application. The password is "delphi".', 'Password Protected Delphi application',  MB_ICONQUESTION + MB_YESNO);
  end;
end.   

--------------------
unit login;

{$MODE Delphi}

interface

uses
  LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes,
  Graphics, Controls, Forms,  Dialogs, StdCtrls;

type
  TLoginForm = class(TForm)
    LogInButton: TButton;
    pwdLabel: TLabel;
    passwordEdit: TEdit;
    procedure LogInButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  public
    class function Execute : boolean;
  end;

implementation

{$R *.lfm}

procedure TLoginForm.LogInButtonClick(Sender: TObject);
begin
  if passwordEdit.Text = 'delphi' then
    ModalResult := mrOK
  else
    ModalResult := mrAbort;
end;

class function TLoginForm.Execute: boolean;
begin
  with TLoginForm.Create(nil) do
  try
    Result := ShowModal = mrOk;
  finally
    Free;
  end;
end;

procedure TLoginForm.FormCreate(Sender: TObject);
begin
  passwordEdit.Text := '';
end;

end.

--------------
unit main;

{$MODE Delphi}

{

Display a LogIn Dialog Before the Main Form of an Application is Created

http://delphi.about.com/od/windowsshellapi/a/password_login.htm

}


interface

uses
  LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMainForm = class(TForm)
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.lfm}

end.       
Lazarus 1.8.0Rc4, Windows 10

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Failed to create win32 control, error 1407: cannot find window class
« Reply #1 on: March 18, 2014, 06:32:28 pm »
You need to move clause 'Application.Initialize;' out of your if clause and put it right after begin reserved word inside your main program block.

Like this:
Code: [Select]
begin
Application.Initialize;
if TLoginForm.Execute then
begin
...

 

TinyPortal © 2005-2018