Solved

How do i get my splash screen to display only once

Posted on 1998-10-06
6
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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