Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: Utf8Test.dproj

Project Structure

Utf8Test.dpr
program Utf8Test;

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

{$R *.res}

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

interface

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

type
  TForm30 = class(TForm)
    btnTrivial: TButton;
    Memo1: TMemo;
    btnAnsi: TButton;
    procedure btnTrivialClick(Sender: TObject);
    procedure btnAnsiClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form30: TForm30;

implementation

{$R *.dfm}

procedure TForm30.btnAnsiClick(Sender: TObject);
var
  str8: Utf8String;
  strAnsi: AnsiString;
begin
  str8 := 'Cantù';
  Memo1.Lines.Add ('UTF-8');
  Memo1.Lines.Add('Length: ' + IntToStr (Length (str8)));
  Memo1.Lines.Add('5: ' + IntToStr (Ord (str8[5])));
  Memo1.Lines.Add('6: ' + IntToStr (Ord (str8[6])));

  strAnsi := str8;
  Memo1.Lines.Add ('ANSI');
  Memo1.Lines.Add('Length: ' + IntToStr (Length (strAnsi)));
  Memo1.Lines.Add('5: ' + IntToStr (Ord (strAnsi[5])));
end;

procedure TForm30.btnTrivialClick(Sender: TObject);
var
  str8: Utf8String;
  str16: string;
begin
  str8 := 'Cantù';
  Memo1.Lines.Add ('UTF-8');
  Memo1.Lines.Add('Length: ' + IntToStr (Length (str8)));
  Memo1.Lines.Add('5: ' + IntToStr (Ord (str8[5])));
  Memo1.Lines.Add('6: ' + IntToStr (Ord (str8[6])));

  str16 := str8;
  Memo1.Lines.Add ('UTF-16');
  Memo1.Lines.Add('Length: ' + IntToStr (Length (str16)));
  Memo1.Lines.Add('5: ' + IntToStr (Ord (str16[5])));
end;

end.
Utf8Test_MainForm.pas.dfm
object Form30: TForm30
  Left = 0
  Top = 0
  Caption = 'Utf8Test'
  ClientHeight = 348
  ClientWidth = 591
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnTrivial: TButton
    Left = 24
    Top = 16
    Width = 75
    Height = 25
    Caption = 'btnTrivial'
    TabOrder = 0
    OnClick = btnTrivialClick
  end
  object Memo1: TMemo
    Left = 152
    Top = 16
    Width = 425
    Height = 321
    TabOrder = 1
  end
  object btnAnsi: TButton
    Left = 24
    Top = 56
    Width = 75
    Height = 25
    Caption = 'btnAnsi'
    TabOrder = 2
    OnClick = btnAnsiClick
  end
end
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù