如何在 Turbo Delphi 上制作带有进度条的启动屏幕?

发布于 2024-07-23 04:50:36 字数 2074 浏览 10 评论 0原文

(单元1.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.

(单元2.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.

(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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天冷不及心凉 2024-07-30 04:50:36

在您的 *.dpr 中,尝试如下操作:

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.

您不需要任何对 FormUtama 类型的引用。

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.

漫雪独思 2024-07-30 04:50:36

在您的项目代码中,您将这样做:

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

实际上,您在创建 Form1 之前正在使用 Form1 中的方法。 这是专门解决问题的...

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...

格子衫的從容 2024-07-30 04:50:36

以下是结论

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.

非常感谢那些回答我问题的人。

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.

没︽人懂的悲伤 2024-07-30 04:50:36

在项目源代码(.dpr 文件)的开始语句之后添加以下代码:

Application.Initialize; //this line exists!
 SplashScreen := TMySplashScreen.Create(nil) ;
 SplashScreen.Show;
 SplashScreen.Update; 

在最终的 Application.Create() 之后和 Application.Run 之前:

SplashScreen.Hide;
SplashScreen.Free;

Add this code after the begin statement of the Project Source code (the .dpr file):

Application.Initialize; //this line exists!
 SplashScreen := TMySplashScreen.Create(nil) ;
 SplashScreen.Show;
 SplashScreen.Update; 

After the final Application.Create() and before Application.Run:

SplashScreen.Hide;
SplashScreen.Free;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文