unit Protmai2;
{$O-}  // Do not remove, Delphi might crash !!!
{$R-}
{$Q-}
{$A+}
interface     

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    f0: TLabel;
    f0d: TLabel;
    f100: TLabel;
    f1000: TLabel;
    f100d: TLabel;
    f1000d: TLabel;
    Bevel1: TBevel;
    Label20: TLabel;
    prom: TLabel;
    promd: TLabel;
    Label26: TLabel;
    Bevel2: TBevel;
    Bevel4: TBevel;
    Bevel5: TBevel;
    Bevel6: TBevel;
    Bevel8: TBevel;
    Bevel9: TBevel;
    Bevel10: TBevel;
    Bevel11: TBevel;
    Label8: TLabel;
    tmlf: TLabel;
    tmlfd: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label15: TLabel;
    Label17: TLabel;
    ResLabel: TLabel;
    Label25: TLabel;
    Label2: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label21: TLabel;
    Bevel3: TBevel;
    Label3: TLabel;
    prouse: TLabel;
    proused: TLabel;
    Label14: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    f0s: TLabel;
    f100s: TLabel;
    f1000s: TLabel;
    tmlfs: TLabel;
    f100ds: TLabel;
    f1000ds: TLabel;
    tmlfds: TLabel;
    f0ds: TLabel;
    Warnlab: TLabel;
    procedure StartItAll(Sender: TObject);
  private
    { Private-Deklarationen }
    FUNCTION  MBox : TMyLargeInteger;
    PROCEDURE UserMessage ( VAR Message ); Message WM_USER+5;
  private
    res     : Array[0..5] OF TMyLargeInteger;
    resstr  : Array[0..5] OF String;
    resstr2 : Array[0..5] OF String;

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

FUNCTION TForm1.MBox : TMyLargeInteger;
BEGIN
  PostMessage(application.mainform.handle, WM_USER+5, 1, 2);
  MessageBox(0, 'Messagebox demo, waiting for click should not be measured',
                'Protest', MB_OK);
END;

PROCEDURE TForm1.UserMessage ( VAR Message );
VAR
  I : Integer;
BEGIN
  i := 0;
  WHILE i < 100000 DO 
    INC(i);
END;

PROCEDURE ConvertTime ( VAR wertstr : String; wert : Double; AsCycles : Boolean );
VAR
  einheit : String;
BEGIN
  IF AsCycles = TRUE THEN BEGIN
    Str(wert:0:0, einheit);
    wertstr := '';
    WHILE Length(einheit) > 3 DO BEGIN
      wertstr := ',' + Copy(einheit, Length(einheit)-2, 3) + wertstr;
      einheit := Copy(einheit, 1, Length(einheit)-3);
    END;
    wertstr := einheit + wertstr;
    exit;
  END;
  wertstr := '0.000µS';
END;

procedure TForm1.StartItAll(Sender: TObject);
VAR
  i, x     : Integer;
  xd       : Real;
  ergebnis : Integer;
  resstrs  : Array[0..5] OF String;
  resstr2s : Array[0..5] OF String;
begin

  FOR i := 0 TO 5 DO
    res[i].quadpart := 0;

  Ergebnis := 0;
  FOR i := 1 TO 100 DO
    res[3].lowpart := res[3].lowpart + TopFunction(Ergebnis).lowpart;

  Ergebnis := 0;
  FOR i := 1 TO 100 DO
    res[1].lowpart := res[1].lowpart + FunctionWith100(Ergebnis,100).lowpart;

  Ergebnis := 0;
  FOR i := 1 TO 100 DO
    res[2].lowpart := res[2].lowpart + FunctionWith1000(Ergebnis,1000).lowpart;

  FOR i := 1 TO 100 DO
    Empty;

  res[4].lowpart := res[4].lowpart + MBox.lowpart;

  FOR i := 0 TO 5 DO BEGIN
    x := res[i].lowpart;
    IF x < 4 THEN
      x := x DIV 100;
    ConvertTime(resstr[i], x, TRUE);
    xd := Round(x);
    ConvertTime(resstr2[i], xd, FALSE);
    IF i < 4 THEN BEGIN
      x := res[i].lowpart;
      ConvertTime(resstrs[i], x, TRUE);
      xd := Round(x);
      ConvertTime(resstr2s[i], xd, FALSE);
    END;
  END;

  f0.caption     := resstr[0];
  f100.caption   := resstr[1];
  f1000.caption  := resstr[2];
  tmlf.caption   := resstr[3];
  prom.caption   := resstr[4];
  prouse.caption := resstr[5];

  f100s.caption  := resstrs[1];
  f1000s.caption := resstrs[2];
  tmlfs.caption  := resstrs[3];

  f0d.caption      := resstr2[0];
  f100d.caption    := resstr2[1];
  f1000d.caption   := resstr2[2];
  tmlfd.caption    := resstr2[3];
  promd.caption    := resstr2[4];
  proused.caption  := resstr2[5];

  f0ds.caption   := resstr2s[0];
  f100ds.caption := resstr2s[1];
  f1000ds.caption:= resstr2s[2];
  tmlfds.caption := resstr2s[3];
  {$IFDEF      PROFILE } ResLabel.Visible := TRUE;  {$ENDIF }
  {$IFNDEF     PROFILE } WarnLab.visible := TRUE;   {$ENDIF }
end;

end.
