views:

687

answers:

6

(Unit1.pas)

    unit Unit1;

    interface

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

    type
      TForm1 = class(TForm)
        Button1: TButton;
        Label1: TLabel;
        Timer1: TTimer;
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure OpenSplash;
        procedure ShowProgress;
        procedure CloseSplash;
      end;

    var
      Form1: TForm1;
          X: Integer;
          Total: Integer;
          Percent: Integer;

    implementation

    {$R *.dfm}
     procedure TForm1.OpenSplash;
    begin
      Label1.Caption := '';
      Show;
      Update;



    end;

procedure TForm1.CloseSplash;
begin
  Form1.Destroy;
end;


procedure TForm1.ShowProgress;
begin
Label1.caption:='';
   Total := 1000;
      for X := 1 to Total do
      begin
        Sleep(5);
        Percent := (x * 100) div Total;
        Label1.caption := StringOfChar('|', Percent) + IntToStr(Percent) + '%';
        Label1.Repaint;

      end;
end;

 procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Close;
  Release;
  Form1 := nil;
end;

end.

(Unit2.pas)

unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    memo1: TMemo;

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}
function Splash: TForm2;
begin
  if Form2 = nil then begin
    Form2 := TForm2.Create(Application);
  end;
  result := Form2;
end;
end.

(*.dpr)

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Form1.OpenSplash;
  Form1.ShowProgress;
  Application.CreateForm(TForm1, Form1);
  Form1.CloseSplash;
  Application.Run;
end.
+2  A: 

In your *.dpr, try something like this:

begin
  Application.Initialize;
  FormSplash := TFormSplash.Create( Application );
  FormSplash.OpenSplash;
  // Do the rest of your initialisation...
  // MAKE SURE THERE'S NO CreateForm FOR FormSplash!
  FormSplash.ShowProgress( "Creating a form..." );
  Application.CreateForm( ... , ... );
  ...
  // When you want to modify the splashscreen, do something like this:
  FormSplash.ShowProgress( "Doing something else..." );
  ...
  // Close the splash screen
  FormSplash.CloseSplash;
  Application.Run;
end.

You shouldn't need any references to your FormUtama type.

moobaa
i've done it like thisprogram Project1;uses Forms, Splash in 'Splash.pas' {FormSplash}, SplashProject in 'SplashProject.pas' {Form1};{$R *.res}begin Application.Initialize; Application.OpenSplash; Application.CreateForm(TForm1, Form1); Splash.CloseSplash; Application.Run;end.still found some error
Otip88
Updated my answer :)
moobaa
I just need 3 process :1. Application.Intialize2.FormSplash.OpenSplash; FormSplash.ShowProgress(FormSplash, TFormSplash);3.Application.CreateForm(FormUtama, TFormUtama); FormSplash.CloseSplash; Application.Run;but still I have same problem with "ShowProgress" on FormUtama
Otip88
Assigning Application as owner when you create the splashform is a waste of processor cycles if you free it yourself (which you didn't do, BTW - you left it hanging around in memory for the entire lifetime of the program run).
Ken White
moobaa
A: 

unit SplashProject;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Splash;

type TFormUtama = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } function Splash: TFormUtama; end;

var FormUtama: TFormUtama;

implementation

{$R *.dfm}

function Splash: TFormUtama; begin
if FormUtama = nil then begin FormUtama := TFormUtama.Create(Application); end; result := FormUtama; end;

procedure TFormUtama.FormCreate(Sender: TObject); procedure AddNumber (vStart, vEnd: Integer); var i : integer; begin for i := vStart to vEnd do begin Memo1.Lines.Add(IntToStr(i)); Sleep(50); end; end; var i : integer; begin
Splash.ShowProgress('Load Data 1');
AddNumber(1, 100);
Splash.ShowProgress('Load Data 2');
AddNumber(101, 200);
Splash.ShowProgress('Load Data 3');
AddNumber(201, 300); end; end.

the error come out on the Bolded font Splash.ShowProgress('Load Data 1'); AddNumber(1, 100); Splash.ShowProgress('Load Data 2'); AddNumber(101, 200); Splash.ShowProgress('Load Data 3'); AddNumber(201, 300);

can you help me?

Otip88
Ummm... ShowProgress is only a method on TFormSplash, not TFormUtama :}
moobaa
what should I do?
Otip88
This is not an answer. Why don't you edit your question instead?
Smasher
sorry my bad, i was not paying attention.
Otip88
+1  A: 

In your project code you are doing like this:

  Form1.OpenSplash;
  Form1.ShowProgress;
  Application.CreateForm(TForm1, Form1);
  Form1.CloseSplash;

Actually you are using methods from Form1 before creating it. This is dedicated to give problems...

Uwe Raabe
thanks!! you open my eyes!!! it works now...
Otip88
A: 

Here are the conclution

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Form1 := TForm1.Create( Application );
  Form1.OpenSplash;
  Form1.ShowProgress;
  Application.CreateForm(TForm2, Form2);
  Form1.CloseSplash;
  Application.Run;
end.

Unit 1

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
    procedure OpenSplash;
    procedure ShowProgress;
    procedure CloseSplash;
  end;

var
  Form1: TForm1;
      X: Integer;
      Total: Integer;
      Percent: Integer;

implementation

{$R *.dfm}
 procedure TForm1.OpenSplash;
begin
  Label1.Caption := '';
  Show;
  Update;



end;

procedure TForm1.CloseSplash;
begin
  Form1.Destroy;
end;


procedure TForm1.ShowProgress;
begin
Label1.caption:='';
   Total := 1000;
      for X := 1 to Total do
      begin
        Sleep(5);
        Percent := (x * 100) div Total;
        Label1.caption := StringOfChar('|', Percent) + IntToStr(Percent) + '%';
        Label1.Repaint;

      end;
end;

end.

Unit 2

unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    memo1: TMemo;

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

end.

Thanks a lot for those who answer my question.

Otip88
+1  A: 

Maybe this is interesting for you.

Ulrich Gerhardt
A: 

I'm trying to use this, Form1 := TForm1.Create( Application ); does not work in D2009. I get [DCC Error] Project.dpr(21): E2029 '.' expected but ':=' found. See below.

Application.Initialize; SplashBar :=TSplashBar.Create(Application); TSplashBar.OpenSplash; TSplashBar.ShowProgress; Application.CreateForm(TForm1, Form1); Application.CreateForm(TAboutBox, AboutBox); TSplashBar.CloseSplash; Application.Run;

[DCC Error] Project.dpr(20): E2029 '.' expected but ':=' found [DCC Error] Project.dpr(21): E2076 This form of method call only allowed for class methods

Any ideas?

I need the progressbar to show the copying of a file on load. When this is done, the program must start and the Splash dissappears. The file is located on an intranet, and is copied to the local machine.

Help please?!

Shaun