Forum > General

[SOLVED]Form2.Show Exception Error

(1/2) > >>

IndianaJones:
Hi all,

I have encountered the following error message when I call the Form2 from the Form1 in the oncreate event.
Is it a bug or restriction for carbon?
Thanks.

FPC 2.4.2-0
Lazarus SVN 29176
Leopard 10.5.8

Blaazen:
I think you call Form2 too early. At that time (Form1 OnCreate) is not Form2 created yet.
Try it call later.

jw:
this doesn't just happen on mac i've had to create what i call a start timer that gets set enabled:=true in the form.activate event and wait for an interval of 1000 or so and have the timer make the calls to open the next form.

or make the call to from2 from form1.onactivate

xenblaise:

--- Quote ---unit Unit1;
{$mode objfpc}{$H+} 

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
Form2.Label1.Caption := 'this is label1 in form_2 called by form_1';
end;

initialization
  {$I unit1.lrs}

end.

--- End quote ---


--- Quote ---unit Unit2;

{$mode objfpc}{$H+} 

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
  Form2: TForm2;

implementation
uses unit1;

procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Show;
Form1.Label1.Caption := 'this is label1 in form_1 called by form_2';
end;

initialization
  {$I unit2.lrs}

end.

--- End quote ---

IndianaJones:

@xenablaise
What would be the case if it is not triggered from the Button click event?

@Blaazen
  Form2:=TForm2.Create(nil);
  Form2.Show;

works in the oncreate event, but Form2 lost its focus, Form1 activated after this procedure executed.

Thanks

Navigation

[0] Message Index

[#] Next page

Go to full version