el stamatakos ha scritto:
Hi All,
 I am trying to use a splash screen before my main application starts. I use 
the following. Does anyone see anything wrong with the below since it does not 
seem to bring up the Splash Screen. Thanks

Lefti
------------------------------------------unit 
Splash------------------------------------------------------------------------------
unit Splash;

{$mode objfpc}{$H+}

interface

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

type

  { TSplashForm }

  TSplashForm = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
end;
var
  SplashForm: TSplashForm;

implementation

{ TSplashForm }

procedure TSplashForm.FormCreate(Sender: TObject);
begin
  sleep(20000);
end;

initialization
  {$I splash.lrs}

end.
------------------------------------------unit 
Splash------------------------------------------------------------------------------

------------------------------------------Main 
project-----------------------------------------------------------------------------
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms
{ you can add units after this }, SQLDBLaz, ProcessDesChild, Unit1, SharedVarsU, SharedLibsU, Splash;

begin
SplashForm:=TSplashForm.Create(Application);
SplashForm.Show;
SplashForm.Paint;
SplashForm.Update;
application.ProcessMessages;
application.Initialize;
what I can see of wrong is that your form is not known by the Application object which is the main progam, and that you attempt to use application methods before initializing it.

//Delay(2000);
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  SplashForm.Hide;
  SplashForm.Close;
  SplashForm.Release;
  SplashForm.Free;
  Application.Run;
end.

------------------------------------------Main 
project-----------------------------------------------------------------------------



You should have two forms, one for the splash screen, the other for your program, and let TApplication handle them.

your file Program.lpr should be sort of:
.......

uses

 {$IFDEF UNIX}{$IFDEF UseCThreads}

 cthreads,

 {$ENDIF}{$ENDIF}

 Interfaces, // this includes the LCL widgetset

 Forms

 { add your units here }, UMyForm, Usplash;

begin

 Application.Initialize;

 Application.CreateForm(TForm2, Form2);

 Application.CreateForm(TForm1, Form1);

 Application.Run;

end.

Then your unit Usplash could be something like:

unit Usplash;

{$mode objfpc}{$H+}

interface

uses

 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,

 ExtCtrls;

type

 { TForm2 }

 TForm2 = class(TForm)

   Label1: TLabel;

   Timer1: TTimer;

   procedure Timer1Timer(Sender: TObject);

 private

   { private declarations }

 public

   { public declarations }

end;
var

Form2: TForm2;
implementation

uses

 UButtons;

{ TForm2 }

procedure TForm2.Timer1Timer(Sender: TObject);

begin

Form1.Show;

Form1.WindowState:=wsNormal;

Timer1.Enabled:=False;

Hide;



end;

initialization

 {$I usplash.lrs}

end.

(Set the appropriate Timer interval for the time you want the Splash to show)

Do not forget, in your main program form to provide an OnClose event handler which executes Form2.Close, because otherwise when you close your main form, the splash form will be hidden, but still running, and your program will never terminate.

Giuliano

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to