Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

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'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  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