Solved

How do i get my splash screen to display only once

Posted on 1998-10-06
6
132 Views
Last Modified: 2010-04-06
How do i get my splash screen to display only once and add somthing to the registry so it won't load the next time the program loads.
0
Comment
Question by:hyper66
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
inter earned 150 total points
ID: 1341986
Hi, do it as follows:

.Splash;
var
  T : TRegistry;
const
  MyKey = 'SOFTWARE\Hyper66\testkey';
begin
  T :=TRegistry.Create;
  try
    T.RootKey := HKEY_LOCAL_MACHINE;
    if not T.KeyExists(MyKey) then
       SplashForm.Show;
    else T.CreateKey(MyKey);
  finally
    T.Free;
  end;
end;

regards, igor
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1341987
Hi,
Here's a way to do it. It has not been tested for typos:

Unit MySplashForm;

Uses ...reg;
  ...
  ...

procedure Splash;
begin
  with TRegistry.Create do
  begin
    if ( OpenKey( '\software\mybasekey\mykey', False ) and ValueExists( 'MyValue' ) and ReadBool( 'MyValue' ) ) then
    begin
      Self.Free; // or something
    end else
    begin
      Show;
      Update;
      OpenKey( '\software\mybasekey\mykey', True );
      WriteBool( 'MyValue', True );
    end;
    Free; // TRegistry class instance
  end;
end;

/// John
0
 

Author Comment

by:hyper66
ID: 1341988
Hello Igor!

   Thank's for replying, I can get a splash screen to display with code listed about but. How do add the code to the project source!! here is the code I am trying to add it to.

================================================================
Splash.dpr
================================================================
program TSplash;

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

{$R *.RES}

begin
   try
    SplashScreen := TSplashScreen.Create(Application);
    SplashScreen.Show;
    SplashScreen.Update;
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
  Repeat
      Application.ProcessMessages;
       Until SplashScreen.CloseQuery;
      SplashScreen.Close;
     finally
    SplashScreen.Free;
  end;
  Application.Run;
end.


================================================================
Splash.pas
================================================================

unit Splash;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, jpeg;

type
  TSplashScreen = class(TForm)
    Timer1: TTimer;
    Image1: TImage;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SplashScreen: TSplashScreen;

implementation

{$R *.DFM}

procedure TSplashScreen.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
end;

procedure TSplashScreen.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
CanClose := Not Timer1.Enabled;
end;

end.


How Can i Add the code above to this code i already have. i tryied to add it but i crash splash.exe everytime.  Thank's Hyper66

                                                     
 
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:hyper66
ID: 1341989
Adjusted points to 150
0
 
LVL 5

Expert Comment

by:inter
ID: 1341990
So first lets change our checking proc as

function DoISplash:boolean;
var
  T : TRegistry;
const
  MyKey = 'SOFTWARE\Hyper66\testkey';
begin
  T :=TRegistry.Create;
  try
    T.RootKey := HKEY_LOCAL_MACHINE;
    Result := not T.KeyExists(MyKey);
    if Result then
      T.CreateKey(MyKey);
    T.CloseKey;
  finally
    T.Free;
  end;
end;

so in your main proc code you can do the following:

var
  doI : boolean;
begin
 DoI := DoISplash;
 try
   if DoI then
   begin
     SplashScreen := TSplashScreen.Create(Application);
     SplashScreen.Show;
     SplashScreen.Update;
   end;
   Application.Initialize;
   Application.CreateForm(TForm1, Form1);
   if DoI then
   begin
     Repeat
       Application.ProcessMessages;
     Until SplashScreen.CloseQuery;
     SplashScreen.Close;
   end;
  finally
   if DoI then SplashScreen.Free;
  end;
  Application.Run;
end.

but it is more convinient to do the following modifications

1 - In the splash form delete Closequerry and Add just OnClose event and inside it set
    Action := caFree;
    also modify TimerEvent as follows
procedure TSplashScreen.Timer1Timer(Sender: TObject);
begin
  Enabled := false;
  Close;
end;
    so when the timer expires the form is closed and freed
2 - Use the following code (the form automatically destroy itself)
.
begin
 if DoISplash then
 begin
   SplashScreen := TSplashScreen.Create(nil);
   SplashScreen.Show;
   SplashScreen.Update;
 end;
 Application.Initialize;
 Application.CreateForm(TForm1, Form1);
 Application.Run;
end.

regards, igor
0
 

Author Comment

by:hyper66
ID: 1341991
Thank's, Igor I could'nt get it to work with T.RootKey := HKEY_LOCAL_MACHINE; but the code work's great without Rootkey any ideas why???
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now