Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: UniApiSpeed.dproj

Project Structure

UniApiSpeed.dpr
program UniApiSpeed;

uses
  Forms,
  UniApi_MainForm in 'UniApi_MainForm.pas' {Form30};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm30, Form30);
  Application.Run;
end.
UniApi_MainForm.pas
unit UniApi_MainForm;

interface

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

type
  TForm30 = class(TForm)
    btnSetWindowText: TButton;
    btnUserName: TButton;
    Memo1: TMemo;
    procedure btnSetWindowTextClick(Sender: TObject);
    procedure btnUserNameClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form30: TForm30;

implementation

{$R *.dfm}

procedure TForm30.btnUserNameClick(Sender: TObject);
var
  I:Integer;
  nSize: DWORD;
  t1: TDateTime;
  str: string;
  pch: PChar;
begin
  nSize := 100;
  SetLength (str, nSize);
  pch := PChar (str);
  t1 := Now;
  for I := 1 to 10000 do
  begin
    GetUserName (pch, nSize);
  end;
  t1 := Now - t1;
  Memo1.Lines.Add ((Sender as TButton).Caption + ' ' +
    FormatDateTime ('ss.zzz', t1));
end;

procedure TForm30.btnSetWindowTextClick(Sender: TObject);
var
  I: Integer;
  t1: TDateTime;
  str: string;
  pch: PChar;
begin
  str := 'Hello';
  pch := PChar (str);
  t1 := Now;
  for I := 1 to 10000 do
  begin
    SetWindowText (handle, pch);
  end;
  t1 := Now - t1;
  Memo1.Lines.Add ((Sender as TButton).Caption + ' ' +
    FormatDateTime ('ss.zzz', t1));
end;

end.
UniApi_MainForm.pas.dfm
object Form30: TForm30
  Left = 343
  Top = 462
  Caption = 'UniApiSpeed'
  ClientHeight = 233
  ClientWidth = 505
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnSetWindowText: TButton
    Left = 16
    Top = 16
    Width = 153
    Height = 25
    Caption = 'btnSetWindowText'
    TabOrder = 0
    OnClick = btnSetWindowTextClick
  end
  object btnUserName: TButton
    Left = 16
    Top = 54
    Width = 153
    Height = 25
    Caption = 'btnUserName'
    TabOrder = 1
    OnClick = btnUserNameClick
  end
  object Memo1: TMemo
    Left = 192
    Top = 18
    Width = 281
    Height = 191
    TabOrder = 2
  end
end
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù