⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainunit.pas

📁 变体类型 变体类型 变体类型
💻 PAS
字号:
unit mainunit;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    ProgressBar1: TProgressBar;
    Label3: TLabel;
    Button3: TButton;
    Button4: TButton;
    Label4: TLabel;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    WasteTime:Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  V1: Variant;
begin
  V1 := 0;
  Form1.ProgressBar1.Position := 0;
  Timer1.Enabled:=True;
  WasteTime:=0;
  Label1.Caption:='Variant类型运行时间:';
  Label1.Font.Color:=ClBlack;
  while V1 < 5000000 do
  begin
   Inc (V1);
   if (V1 mod 50000) = 0 then
    begin
      ProgressBar1.Position := V1 div 50000;
      Application.ProcessMessages;
    end;
  end;
  Timer1.Enabled:=False;
  Label1.Caption :=Label1.Caption+IntToStr(WasteTime)+'秒.';
  Label1.Font.Color:=ClRed;
  WasteTime:=0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 WasteTime:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
 WasteTime:=WasteTime+1;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  V1: Integer;
begin
  V1 := 0;
  Form1.ProgressBar1.Position := 0;
  Timer1.Enabled:=True;
  WasteTime:=0;
  Label2.Caption:='Integer整型运行时间:';
  Label2.Font.Color:=ClBlack;
  while V1 < 5000000 do
  begin
   Inc (V1);
   if (V1 mod 50000) = 0 then
    begin
      ProgressBar1.Position := V1 div 50000;
      Application.ProcessMessages;
    end;
  end;
  Timer1.Enabled:=False;
  if (WasteTime<1 )then
   Label2.Caption :=Label2.Caption+'少于1秒.'
  else
   Label2.Caption :=Label2.Caption+IntToStr(WasteTime)+'秒.';
  Label2.Font.Color:=ClBlue;
  WasteTime:=0;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  V1: Double;
begin
  V1 := 0;
  Form1.ProgressBar1.Position := 0;
  Timer1.Enabled:=True;
  WasteTime:=0;
  Label4.Caption:='Real实型运行时间:';
  Label4.Font.Color:=ClBlack;
  while V1 < 5000000 do
  begin
    V1:=V1+1;
    if (Round(V1) mod 50000) = 0 then
    begin
      ProgressBar1.Position :=Round(V1) div 50000;
      Application.ProcessMessages;
    end;
  end;
  Timer1.Enabled:=False;
  if (WasteTime<1 )then
   Label4.Caption :=Label4.Caption+'少于1秒.'
  else
   Label4.Caption :=Label4.Caption+IntToStr(WasteTime)+'秒.';
  Label4.Font.Color:=ClYellow;
  WasteTime:=0;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 Close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -