problems with creating a splash-screen

Hi experts,

with the code quoted below I try to create a splash-screen. Unfortunately it does not work as
desired.

The code is syntactically correct, however when I run my program, the splash-screen is not displayed.

Can you please tell me, what I am doing wrong here?



program WinPosh;

uses
  Forms,
  Dialogs,
  SysUtils,
  filectrl,
  WP_MAINMENUE in 'WP_MAINMENUE.PAS' {frmMainMenu},
  WP_Setup in 'WP_SETUP.PAS' {frmWP_Setup},
  WP_global_module in 'WP_global_module.pas',
  WP_SplashScreen in 'WP_SplashScreen.pas' {frmWP_SplashScreen};

{$R *.RES}

begin
  Application.Initialize;
  Application.HelpFile := 'WINPOSH.HLP';
  Application.CreateForm(TfrmMainMenu, frmMainMenu);
  Application.CreateForm(TfrmWP_Setup, frmWP_Setup);
  Application.CreateForm(TfrmWP_SplashScreen, frmWP_SplashScreen);
  if (FileExists(ExtractFilePath(Application.ExeName) +
     'winposh.ini')=false) then  CreateIniFile;
  Application.Run
end.  

mathesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ginsonicConnect With a Mentor Commented:
I think that Application.Initialize most be first .
Tested my code and work for me .
0
 
ginsonicCommented:
I think that you must add to splash form something alike:



procedure TfrmWP_SplashScreen.FormShow(Sender: TObject);
begin
  SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;
0
 
ginsonicCommented:
OR:

Application.Initialize;
{my suggestion}
Application.CreateForm(TfrmWP_SplashScreen, frmWP_SplashScreen);
frmWP_SplashScreen.Show;
frmWP_SplashScreen.Update;
{my suggestion}
Application.HelpFile := 'WINPOSH.HLP';
Application.CreateForm(TfrmMainMenu, frmMainMenu);
Application.CreateForm(TfrmWP_Setup, frmWP_Setup);
if (FileExists(ExtractFilePath(Application.ExeName) +
    'winposh.ini')=false) then  CreateIniFile;
{my suggestion}
frmWP_SplashScreen.Hide;
frmWP_SplashScreen.Free;
{my suggestion}
Application.Run


0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ginsonicCommented:
And don't forget to add to main form :

procedure TfrmMainMenu.FormCreate(Sender: TObject);
var
  CurrentTime: LongInt;
begin
  CurrentTime := GetTickCount div 1500;
  while ( (GetTickCount div 1500) < (CurrentTime + 4) ) do
    { nothing };
end;
0
 
mathesAuthor Commented:
Dear gnsonic,

I used the following freeware code when I created my own splashscreen:

program Project1;

uses
  Forms,
  Windows,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {SplashScreen};

{$R *.RES}

begin
  SplashScreen := TSplashScreen.Create(Application);
  SplashScreen.Show;
  Application.Initialize;
  SplashScreen.Update;
  Sleep(1000); // Or a delay command.
  Application.CreateForm(TForm1, Form1);
  SplashScreen.Hide;
  SplashScreen.Free;
  Application.Run;
end.

(Source: www.SwissDelphiCenter.ch)

Do you think that this sample code can work?


0
 
kretzschmarCommented:
i use this in one of my projects

program BP;

uses
  Forms,
  BP_u1 in 'BP_u1.pas' {Form1},
  BP_u3 in 'BP_u3.pas' {F_AG: TFrame},
  BP_u2 in 'BP_u2.pas' {F_PResource: TFrame},
  fr_prg_u in 'fr_prg_u.pas' {fr_prg: TFrame},
  fr_pr_u in 'fr_pr_u.pas' {fr_pr: TFrame},
  fr_prc_u in 'fr_prc_u.pas' {fr_prcal: TFrame},
  fr_agg_u in 'fr_agg_u.pas' {fr_agg: TFrame},
  fr_ag_u in 'fr_ag_u.pas' {fr_ag: TFrame},
  fr_fp_u in 'fr_fp_u.pas' {fr_agl: TFrame},
  fr_fpg_u in 'fr_fpg_u.pas' {fr_aglg: TFrame},
  BP_u4 in 'BP_u4.pas' {F_FP: TFrame},
  bp_progress_u in 'bp_progress_u.pas' {frmProgress},
  bp_Splash_u in 'bp_Splash_u.pas' {f_Splash},
  fr_ppl_u in 'fr_ppl_u.pas' {fr_ppl: TFrame},
  f_ppo_u in 'f_ppo_u.pas' {fr_ppo: TFrame},
  repBeleg1 in 'repBeleg1.pas' {qr_Beleg1: TQuickRep},
  repBeleg2 in 'repBeleg2.pas' {qrBeleg2: TQuickRep},
  uRepBBPO in 'uRepBBPO.pas' {RepBBPO: TQuickRep};

{$R *.RES}

begin
  Application.Initialize;
  f_Splash := tf_Splash.Create(Application);
  f_Splash.Show;
  f_Splash.BringToFront;
  Application.ProcessMessages;
  try
    Application.HelpFile := 'DruckAuftragHilfe.hlp';
    Application.Title := 'Vistaworks PPS';
    Application.CreateForm(TForm1, Form1);
    Application.CreateForm(TRepBBPO, RepBBPO);
  except
    Raise;
    Application.Terminate;
  end;
  f_Splash.Release;
  Application.Run;
end.

meikl ;-)
0
 
robert_marquardtCommented:
That is my version:
  Application.Initialize;
  SplashScreen := TSplashScreen.Create(Application);
  SplashScreen.Show;
  SplashScreen.Refresh;
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;

and the splash screen form:
unit Splash;

interface

uses
  Windows, Forms, Graphics, Controls, Classes, ExtCtrls, jpeg, StdCtrls;

type
  TSplashScreen = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    procedure Timer1Timer(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  public
  end;

var
  SplashScreen: TSplashScreen;
  SplashExists: Boolean = False;

implementation

{$R *.DFM}

uses
  JCLGraphics;

procedure TSplashScreen.Timer1Timer(Sender: TObject);
begin
  Close;
end;

procedure TSplashScreen.Image1Click(Sender: TObject);
begin
  Timer1.Free;
  Close;
end;

procedure TSplashScreen.FormCreate(Sender: TObject);
var
 HRegion: HRGN;
begin
  SplashExists := True;
  // from Jedi Code Library
  HRegion := CreateRegionFromBitmap(Image1.Picture.Bitmap, $FFFFFF, rmExclude);
  SetWindowRgn(Handle, HRegion, False);
end;

procedure TSplashScreen.FormDestroy(Sender: TObject);
begin
  SplashExists := False;
end;

end.

The refinement is that the splash screen destroys itself by a timer without slowin down app start.
It also closes on click which is something i want for all splash screens.

0
 
mathesAuthor Commented:

Hi experts,

thank you all for your feedback. I found out that all your suggestions work well in my demo sources.

Meikl: I would like to reward you with points, too.

Please post a dummy comment to my other question, and I will give you points, too.
0
 
mathesAuthor Commented:
Dear Robert,

your solution works very well too. I will ask a question especially to you. Pl4ease post a dummy comment and I will reward you with points, too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.