Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: LatinTest.dproj

Project Structure

LatinTest.dpr
program LatinTest;

uses
  Forms,
  LatinTest_MainForm in 'LatinTest_MainForm.pas' {FormLatinTest};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TFormLatinTest, FormLatinTest);
  Application.Run;
end.
LatinTest_MainForm.pas
unit LatinTest_MainForm;

interface

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

type
  TFormLatinTest = class(TForm)
    btnNewType: TButton;
    Memo1: TMemo;
    btnCompareCharSet: TButton;
    btnCyrillic: TButton;
    procedure btnNewTypeClick(Sender: TObject);
    procedure btnCompareCharSetClick(Sender: TObject);
    procedure btnCyrillicClick(Sender: TObject);
  private
    procedure Log (const strMsg: string);
  public
  end;

var
  FormLatinTest: TFormLatinTest;

implementation

{$R *.dfm}

type
  Latin1String = type AnsiString(28591);
  CyrillicString = type Ansistring(1251);

procedure TFormLatinTest.btnCompareCharSetClick(Sender: TObject);
var
  str1: Latin1String;
  str2: AnsiString;
  I: Integer;
begin
  for I := 128 to 255 do
  begin
    str1 := str1 + AnsiChar (I);
    str2 := str2 + AnsiChar (I); // copies the value without converting it
  end;

  for I := 0 to 15 do
  begin
    Log (IntToStr (128 + I*8) + ' - ' + IntToStr (128 + I*8 + 7));
    Log ('Lati: ' + Copy (str1, 1 + i*8, 8));
    Log ('Ansi: ' + Copy (str2, 1 + i*8, 8));
  end;
end;

procedure TFormLatinTest.btnCyrillicClick(Sender: TObject);
var
  str1: CyrillicString;
  I: Integer;
begin
  str1 := 'a string with an accent: Cantù';
  Log ('String: ' + str1);
  Log ('Last char: ' + IntToStr (Ord (str1[Length(str1)])));
  Log('ElemSize: ' + IntToStr (StringElementSize (str1)));
  Log('Length: ' + IntToStr (Length (str1)));
  Log ('CodePage: ' + IntToStr (StringCodePage (str1)));

  str1 := '';
  for I := 150 to 250 do
    str1 := str1 + CyrillicString(AnsiChar (I));
  Log ('High end chars: ' + str1);
end;

procedure TFormLatinTest.btnNewTypeClick(Sender: TObject);
var
  str1: Latin1String;
begin
  str1 := 'a string with an accent: Cantù';
  Log ('String: ' + str1);
  Log ('Last char: ' + IntToStr (Ord (str1[Length(str1)])));
  Log('ElemSize: ' + IntToStr (StringElementSize (str1)));
  Log('Length: ' + IntToStr (Length (str1)));
  Log ('CodePage: ' + IntToStr (StringCodePage (str1)));
end;


procedure TFormLatinTest.Log (const strMsg: string);
begin
  Memo1.Lines.Add (strMsg);
end;

end.
LatinTest_MainForm.pas.dfm
object FormLatinTest: TFormLatinTest
  Left = 0
  Top = 0
  Caption = 'LatinTest'
  ClientHeight = 292
  ClientWidth = 601
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnNewType: TButton
    Left = 16
    Top = 8
    Width = 122
    Height = 25
    Caption = 'btnNewType'
    TabOrder = 0
    OnClick = btnNewTypeClick
  end
  object Memo1: TMemo
    Left = 144
    Top = 8
    Width = 449
    Height = 273
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = 'Lucida Console'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
  end
  object btnCompareCharSet: TButton
    Left = 16
    Top = 71
    Width = 122
    Height = 25
    Caption = 'btnCompareCharSet'
    TabOrder = 2
    OnClick = btnCompareCharSetClick
  end
  object btnCyrillic: TButton
    Left = 16
    Top = 40
    Width = 122
    Height = 25
    Caption = 'btnCyrillic'
    TabOrder = 3
    OnClick = btnCyrillicClick
  end
end
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù