Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do i get my splash screen to display only once

Posted on 1998-10-06
6
Medium Priority
?
145 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 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