Solved

How do i get my splash screen to display only once

Posted on 1998-10-06
6
133 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 262
Delphi 10 Seattle Dataset Actions 5 78
Mydac connection data base issue 3 139
Base1 Encode/Decode 3 67
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

911 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

19 Experts available now in Live!

Get 1:1 Help Now