Recent

Author Topic: Open form from console?  (Read 1484 times)

Kugler737

  • Newbie
  • Posts: 1
Open form from console?
« on: February 10, 2018, 04:03:27 pm »
Hello, I am new here so I hope I don't write to a bad theard...

I have a little problem... Maybe I am totally wrong, but I wanted to open Form window during run of console program.. Is it possible? If so.. what is wrong with my code?

Project:
program project1;

uses Unit1, Classes, SysUtils, FileUtil, Forms, Controls, Graphics,
  Dialogs, StdCtrls, Interfaces, Crt;


begin
  Write('Hello');
  Readln;
  Form1.Show;
end.
                 



Unit:
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Crt;

type

  { TForm1 }

  TForm1 = class(TForm)
    Press_me: TButton;
    procedure Press_meClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Press_meClick(Sender: TObject);
begin

end;

end.
                                                                               


When I run it, so I have EXTERNAL:SIGSEGV
include\customform.inc on line 2307

Is there something wrong or shall I use other way for opening a form window?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Open form from console?
« Reply #1 on: February 10, 2018, 04:08:18 pm »
forms are dynamic classes, they need to be created first.

 I dont' see where you are doing this?

 Form1 := TForm.CreateNew..... at the start somewhere.

Then..
 Form1.Show etc..
also beware the Tapplication should also be there, I don't see that ether.

 Try that.


The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Open form from console?
« Reply #2 on: February 10, 2018, 04:11:22 pm »
That's a bit unusual.

You can try to add LCL as a dependancy to project1, but I think this is not enough to initialize the widgetset.

Another approach would be to just make a standard Lazarus application and put the "Hello World" part just before "Application.Initialize".
And if you are on Windows, then make sure that you uncheck "Win32 gui application" in Project Options->Compiler Options->Config and Target.

Bart

 

TinyPortal © 2005-2018