Recent

Author Topic: [SOLVED] Call GUI Form from Console application with error.  (Read 4661 times)

ezikoh

  • New Member
  • *
  • Posts: 32
Hello

I programming a proyect type Console Application, in the source I need call GUI Form, but when execute code show the following error in runtime:

Failed to create win32 control, error: 1407 : No se ha encontrado la clase de ventana.
[FORMS.PP] ExceptionOccurred
  Sender=Exception
  Exception=Failed to create win32 control, error: 1407 : No se ha encontrado la clase de ventana.
  Stack trace:
  $000000010016FF14 line 243 of win32wscontrols.pp
  $0000000100185DC6 line 441 of win32wsforms.pp
  $0000000100127D11 line 7455 of include/wincontrol.inc
  $000000010003B6E3 line 23 of include/scrollingwincontrol.inc
  $000000010004261D line 2592 of include/customform.inc
  $0000000100043785 line 3058 of include/customform.inc
  $0000000100127390 line 7365 of include/wincontrol.inc
  $0000000100128A78 line 7811 of include/wincontrol.inc
  $000000010011FB07 line 3455 of include/wincontrol.inc
  $000000010011F79F line 3506 of include/wincontrol.inc
  $0000000100136DA3 line 5463 of include/control.inc
  $0000000100134AA5 line 4299 of include/control.inc
  $0000000100134BE5 line 4273 of include/control.inc
  $000000010003D72A line 487 of include/customform.inc
  $0000000100041D27 line 2206 of include/customform.inc
  $000000010000300A line 80 of project1.lpr
 
I use the lazarus 1.6 with FPC 3.0 in x64bits.

My code for calling is:

...
var
  Application: LAppConsolev1;
  objForm : TForm1;
begin

  Application:=LAppConsolev1.Create(nil);
  Application.Title:='LAppConsolev1';
  Application.Initialize;

  objForm := TForm1.Create(nil);
  objForm.Show;

end.   

Where TForm1 is defined in another file, and is a simple form with a label, textfield and one button.

I search in internet by I can not resolve the execution problem. The compilation is ok but not execute.

¿Could someone please help me to solve the problem?

Thank you.
« Last Edit: April 18, 2016, 05:56:37 pm by ezikoh »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Call GUI Form from Console application with error.
« Reply #1 on: April 11, 2016, 06:48:20 pm »
Sorry, I don't think you can mix and match Console and GUI applications.  I certainly can't think of any other console program program I've ever come across having a GUI.

Can you re-write your app entirely as a GUI?   Or, can you break them into two different projects, and in the console use TProcess to automate the GUI app?
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

ezikoh

  • New Member
  • *
  • Posts: 32
Re: Call GUI Form from Console application with error.
« Reply #2 on: April 11, 2016, 08:12:05 pm »
Hello Mike, Yes I can re-write de app entirely as a GUI, and I think that is better.

Thank you.

Thaddy

  • Hero Member
  • *****
  • Posts: 18529
  • Here stood a man who saw the Elbe and jumped it.
Re: Call GUI Form from Console application with error.
« Reply #3 on: April 12, 2016, 07:16:41 am »
It is perfectly possible under windows to mix and match console with gui. All you have to do is create your GUI project as {$apptype console} and your GUI application has a console too.
Now it depends on when and where you need your GUI form.
1) It maybe that it should immediately show: nothing extra
2) It may be that you want the form(s) hidden: Just call hide or set a property visble at design time.
3) It maybe that you want to create your forms manually: proceed as can be found in the wiki topic.

All of these work in both Delphi and Lazarus under win32/64. Not sure about other platforms.
[edit]
Note that you have to provide some - but not all - console handling yourself.
« Last Edit: April 12, 2016, 10:44:23 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ezikoh

  • New Member
  • *
  • Posts: 32
Re: Call GUI Form from Console application with error.
« Reply #4 on: April 18, 2016, 04:02:24 pm »
Thank you, for your help.

 

TinyPortal © 2005-2018