Recent

Author Topic: OnIdle is called during Application.CreateForm(s) at win32  (Read 6614 times)

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
OnIdle is called during Application.CreateForm(s) at win32
« on: October 10, 2012, 08:54:28 pm »
I'm using Application.OnIdle to run some init procedures. It worked for years (and still doesn't make any problem with Gtk2 and win64) but init is called now at win32 executable while running CreateForm (fmStatistics.<>:=... but it is nil). This results in runtime error 210 because I try to access data that has not been created. The code looks like this:

Code: [Select]
procedure TfmMain.FormShow(Sender: TObject);
begin
  // create something
  Initialized:=false;
  Application.OnIdle:=@FormIdle;
end;

procedure TfmMain.FormIdle(Sender: Tobject; var Done: boolean);
begin
  if not Initialized then Initialize;
  //some other stuff, e.g. OpenGL invalidate
end;

procedure TfmMain.Initialize;
begin
  Initialized:=true;
  //setup something
  //here fmStatistics is accessed but not created
end;

program Scrabble3D;

{$mode objfpc}
...
begin
  Application.Initialize;
  Application.CreateForm(TfmMain, fmMain);
  Application.CreateForm(TfmWordSearch, fmWordSearch);
  Application.CreateForm(TfmNewGame, fmNewGame);
  Application.CreateForm(TfmAbout, fmAbout);
  Application.CreateForm(TfmNetwork, fmNetwork);
  Application.CreateForm(TfmRemote, fmRemote);
  Application.CreateForm(TfmGameOptions, fmGameOptions);
  Application.CreateForm(TfmWelcome, fmWelcome);
  Application.CreateForm(TfmStatistics, fmStatistics);
  Application.Run;
end.

I added a "if assigned(fmStatistics) then" before Initialize, but I guess it should be fixed somewhere else.

FPC 2.6.0 at all platforms, Lazarus 1.1 r38971M FPC 2.6.0 x86_64-linux-qt (and something similar from SVN on win32@XP).
Lazarus 1.7 (SVN) FPC 3.0.0

 

TinyPortal © 2005-2018