Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco


Home: Code Repository: Mastering Delphi 6

Chapter 09 - Project KPreview

Project Structure

KPreview.dpr
program KPreview;

uses
  Forms,
  KPrevF in 'KPrevF.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
KPrevF.pas
unit KPrevF;

interface

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

type
  TForm1 = class(TForm)
    RadioPreview: TRadioGroup;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure RadioPreviewClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.RadioPreviewClick(Sender: TObject);
begin
  KeyPreview := RadioPreview.ItemIndex <> 0;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  case RadioPreview.ItemIndex of
    1: //  Enter = Tab
      if Key = #13 then
      begin
        Key := #0;
        Perform (CM_DialogKey, VK_TAB, 0);
      end;
    2: //  Type in Caption
    begin
      if Key = #8 then // backspace: remove last char
        Caption := Copy (Caption, 1,
          Length (Caption) - 1)
      else if Key = #13 then // enter: stop operation
        RadioPreview.ItemIndex := 0
      else // anything else: add character
        Caption := Caption + Key;
      Key := #0;
    end;
    3: // Skip vowels
      if Key in ['a', 'e', 'i', 'o', 'u',
          'A', 'E', 'I', 'O', 'U'] then
        Key := #0;
  end;
end;

end.
KPrevF.dfm
object Form1: TForm1
  Left = 168
  Top = 113
  Width = 545
  Height = 250
  Caption = 'Key Preview'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  OnKeyPress = FormKeyPress
  PixelsPerInch = 96
  TextHeight = 13
  object RadioPreview: TRadioGroup
    Left = 16
    Top = 16
    Width = 209
    Height = 177
    Caption = 'Preview Options'
    ItemIndex = 0
    Items.Strings = (
      'None'
      'Enter = Tab'
      'Type in Caption'
      'Skip vowels')
    TabOrder = 0
    OnClick = RadioPreviewClick
  end
  object Edit1: TEdit
    Left = 264
    Top = 48
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit1'
  end
  object Edit2: TEdit
    Left = 264
    Top = 80
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'Edit2'
  end
  object Edit3: TEdit
    Left = 264
    Top = 112
    Width = 121
    Height = 21
    TabOrder = 3
    Text = 'Edit3'
  end
end