Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: FromAsciiToUnicode.dproj

Project Structure

FromAsciiToUnicode.dpr
program FromAsciiToUnicode;

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

{$R *.res}

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

interface

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

type
  TForm30 = class(TForm)
    StringGrid1: TStringGrid;
    btnAscii7: TButton;
    StatusBar1: TStatusBar;
    btnUnicode: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    btnEuro: TButton;
    btnAscii8: TButton;
    btnGrapheme: TButton;
    procedure btnAscii7Click(Sender: TObject);
    procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnUnicodeClick(Sender: TObject);
    procedure btnEuroClick(Sender: TObject);
    procedure btnAscii8Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnGraphemeClick(Sender: TObject);
  private
    procedure ClearGrid;
    { Private declarations }
  public

  end;

var
  Form30: TForm30;

implementation

{$R *.dfm}

function GetCharDescr (nChar: Integer): string;
begin
  Result := 'Char #' + IntToStr (nChar) + ' [' + Char (nChar) + ']';
end;

procedure TForm30.btnAscii7Click(Sender: TObject);
var
  I: Integer;
begin
  ClearGrid;
  for I := 32 to 127 do
    StringGrid1.Cells [I mod 16 + 1, I div 16 + 1]
      := AnsiChar (I);
end;

procedure TForm30.btnAscii8Click(Sender: TObject);
var
  I: Integer;
begin
  ClearGrid;
  for I := 32 to 255 do
  begin
    StringGrid1.Cells [I mod 16 + 1, I div 16 + 1] := AnsiChar (I);
  end;
end;

procedure TForm30.ClearGrid;
var
  I: Integer;
begin
  // clean content
  for I := 0 to 255 do
    StringGrid1.Cells[I mod 16 + 1, I div 16 + 1] := '';
end;

procedure TForm30.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  // refresh border
  for I := 0 to 16 do
  begin
    StringGrid1.Cells[I + 1, 0] := IntToStr (I);
    StringGrid1.Cells[0, I + 1] := IntToStr (I*16);
  end;
end;

procedure TForm30.btnUnicodeClick(Sender: TObject);
var
  I: Integer;
begin
  ClearGrid;
  for I := 32 to 255 do
  begin
    StringGrid1.Cells [I mod 16 + 1, I div 16 + 1] := Char (I);
  end;
end;

procedure TForm30.btnEuroClick(Sender: TObject);
var
  aChar: AnsiChar;
  uChar: Char;
begin
  aChar := '€';
  uChar := '€';
  ShowMessage ('€ for AnsiChar is ' + IntToStr (Ord (aChar)));
  ShowMessage ('€ for UnicodeChar is ' + IntToStr (Ord (uChar)));
end;

procedure TForm30.btnGraphemeClick(Sender: TObject);
var
  str: string;
begin
  str := {#0$0061+ }#0$0300;
 ShowMessage (str);
end;

procedure TForm30.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  gc: TGridCoord;
  nChar: Integer;
begin
  gc := StringGrid1.MouseCoord(X, Y);
  nChar := (gc.Y - 1) * 16 + (gc.X - 1);
  StatusBar1.SimpleText := GetCharDescr (nChar);
end;

end.
FromAscii_MainForm.pas.dfm
object Form30: TForm30
  Left = 0
  Top = 0
  Caption = 'FromAsciiToUnicode'
  ClientHeight = 452
  ClientWidth = 577
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Lucida Sans Unicode'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 15
  object StatusBar1: TStatusBar
    Left = 0
    Top = 433
    Width = 577
    Height = 19
    Panels = <>
    SimplePanel = True
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 145
    Height = 433
    Align = alLeft
    TabOrder = 1
    DesignSize = (
      145
      433)
    object btnAscii7: TButton
      Left = 16
      Top = 16
      Width = 105
      Height = 25
      Caption = 'Ascii-7'
      TabOrder = 0
      OnClick = btnAscii7Click
    end
    object btnUnicode: TButton
      Tag = 1
      Left = 16
      Top = 98
      Width = 105
      Height = 25
      Caption = 'Unicode 32-256'
      TabOrder = 1
      OnClick = btnUnicodeClick
    end
    object btnEuro: TButton
      Left = 16
      Top = 394
      Width = 105
      Height = 25
      Anchors = [akLeft, akBottom]
      Caption = 'Euro'
      TabOrder = 2
      OnClick = btnEuroClick
    end
    object btnAscii8: TButton
      Left = 16
      Top = 56
      Width = 105
      Height = 25
      Caption = 'Ascii-8'
      TabOrder = 3
      OnClick = btnAscii8Click
    end
    object btnGrapheme: TButton
      Left = 16
      Top = 360
      Width = 105
      Height = 25
      Caption = 'btnGrapheme'
      TabOrder = 4
      OnClick = btnGraphemeClick
    end
  end
  object Panel2: TPanel
    Left = 145
    Top = 0
    Width = 432
    Height = 433
    Align = alClient
    TabOrder = 2
    object StringGrid1: TStringGrid
      Left = 1
      Top = 1
      Width = 430
      Height = 431
      Align = alClient
      ColCount = 17
      DefaultColWidth = 24
      RowCount = 17
      TabOrder = 0
      OnMouseMove = StringGrid1MouseMove
    end
  end
end
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù