Arsip: [ASK] Mematikan Splash Screen ???

 
user image
more 13 years ago

RoenZ

Hi all... Saya mau tanya.... Misalnya di program saya ada 2 form, form 1 adalah splash screen dan form kedua adalah form utama....... klo program di-run pertama muncul splash screen selama 2 detik trus keluar form kedua (form utama)..... Yang menjadi pertanyaan adalah bisa nga form 1 dimatikan tapi bukan dengan cara :

form1.hide;
form2.show;
timer1.enabled:=false;
klo pakai cara tersebut kan form1 bukan dimatikan tetapi cuman di-hide doank ??? ada cara cara lain nga supaya form1 itu benar mati sedangkan form2 tetap jalan ?? Thx
user image
more 13 years ago

DelphiExpert

modifikasi splash screen form anda sebagai berikut:

type
  TSplashScreenForm = class(TForm)
    procedure SplashScreenFormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
  private
  ...
  public
    class procedure Execute(const Delay: Cardinal);
  end;
implementation
class procedure TSplashScreenForm.Execute(const Delay: Cardinal);
var Splash: TSplashScreenForm;
begin
  Splash:= TSplashScreenForm.Create(nil);
  try
    Splash.Timer1.Interval:= Delay;
    Splash.Timer1.Enabled:= True;
    Splash.Timer1.Show;
  except
    Splash.Free;
  end;
end;
procedure TSplashScreenForm.SplashScreenFormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:= caFree; // this will permanently destroy the TSplashScreenForm object
end;
procedure TSplashScreenForm.Timer1Timer(Sender: TObject);
begin
  Close; // call OnClose, set Action flag = caFree
end;
gimana cara pakenya? 1. Bisa di OnCreate mainform

procedure MainFormCreate(Sender: TObject);
begin
  TSplashScreenForm.Execute(2000); // muncul selama 2 detik
end;
2. atau di project file

program Project1;
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
  Application.Initialize;
  TSplashScreenForm.Execute(2000); // muncul selama 2 detik
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
user image
more 13 years ago

mat_koder

@RoenZ : Dengan logika semacam itu, bisa jadi 2 form tsb muncul overlap dalam waktu yg sama. Apa ngga sebaiknya main form muncul sesaat setelah splash screen mati/closed ?
user image
more 13 years ago

ozan

program Splash;
uses
  Forms,
  frm_Splash in 'frm_Splash.pas' {fm_Splash},
  frm_Main in 'frm_Main.pas' {fm_Main};
{$R .res}
begin
  Application.Initialize;
  Application.CreateForm(Tfm_Main,fm_Main);
  fm_Main.Hide;
  fm_Main.Update;
  fm_Main.Refresh;
  Application.CreateForm(Tfm_Splash, fm_Splash);
  fm_Splash.Show;
  while fm_Main.splash_visible do
    Application.ProcessMessages;
  fm_Main.Show;
  Application.Run;
end.
[/pas][/code]
unit frm_Main;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  Tfm_Main = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    splash_visible:Boolean;
  end;
var
  fm_Main: Tfm_Main;
implementation
{$R  .dfm}
procedure Tfm_Main.FormCreate(Sender: TObject);
begin
  splash_visible:=False;
end;
procedure Tfm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Application.Terminate;
end;
end.
unit frm_Splash;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
type
  Tfm_Splash = class(TForm)
    Timer1: TTimer;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  fm_Splash: Tfm_Splash;
implementation
uses Frm_Main;
{$R *.dfm}
procedure Tfm_Splash.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  fm_Main.splash_visible:=False;
  Action:= caFree; 
end;
procedure Tfm_Splash.Timer1Timer(Sender: TObject);
begin
  Close; 
end;
procedure Tfm_Splash.FormCreate(Sender: TObject);
begin
  fm_Main.splash_visible:=True;
  Timer1.Interval:= 2000;
  Timer1.Enabled:= True;
end;
end.
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com