Хм... Никто не отвечает, а человек, вижу, приходит на форум, возможно, ещё ждёт. Если так, то предложу я чего-нибудь. =)
Задачка-то несложная. Форме задаем свойство KeyPreview=True. Кладём на нее компонент TChart, задаём тип графика в
Horiz. Bar. Ну, там пару-другую компонент TLabel для отображения символа нажатой клавиши и количества нажатий. И всё — пишем обработчики.
pas-файл:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: THorizBarSeries;
SymbolLabel: TLabel;
Label2: TLabel;
Label3: TLabel;
PressCountLabel: TLabel;
ResetBtn: TButton;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
private
{ Private declarations }
PressCount: Cardinal;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not ((Key >= Ord('A')) and (Key <= Ord('Z'))) then Exit;
SymbolLabel.Caption := Chr(Key);
Inc(PressCount);
PressCountLabel.Caption := IntToStr(PressCount);
Chart1.Series[0].XValue[Key - Ord('A')] := Chart1.Series[0].XValue[Key - Ord('A')] + 1;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Char;
begin
PressCount := 0;
Chart1.Series[0].Clear;
for i := 'a' to 'z' do Chart1.Series[0].AddXY(0, Ord(i), i, clGreen);
end;
procedure TForm1.ResetBtnClick(Sender: TObject);
var
i: Char;
begin
PressCount := 0;
Chart1.Series[0].Clear;
for i := 'a' to 'z' do Chart1.Series[0].AddXY(0, Ord(i), i, clGreen);
end;
end.
dfm-файл:
Код:
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 497
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
KeyPreview = True
OldCreateOrder = False
OnCreate = FormCreate
OnKeyDown = FormKeyDown
DesignSize = (
688
463)
PixelsPerInch = 96
TextHeight = 13
object SymbolLabel: TLabel
Left = 592
Top = 392
Width = 89
Height = 65
Alignment = taCenter
Anchors = [akRight, akBottom]
AutoSize = False
Font.Charset = RUSSIAN_CHARSET
Font.Color = clWindowText
Font.Height = -48
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label2: TLabel
Left = 592
Top = 376
Width = 89
Height = 13
Alignment = taCenter
Anchors = [akRight, akBottom]
AutoSize = False
Caption = 'Symbol:'
end
object Label3: TLabel
Left = 464
Top = 376
Width = 113
Height = 13
Alignment = taCenter
Anchors = [akRight, akBottom]
AutoSize = False
Caption = 'Key pressing count:'
end
object PressCountLabel: TLabel
Left = 464
Top = 392
Width = 113
Height = 25
Alignment = taCenter
Anchors = [akRight, akBottom]
AutoSize = False
Caption = '0'
end
object Chart1: TChart
Left = 0
Top = 0
Width = 688
Height = 369
BackWall.Brush.Color = clWhite
BackWall.Brush.Style = bsClear
Title.Text.Strings = (
'TChart')
Title.Visible = False
BottomAxis.Automatic = False
BottomAxis.AutomaticMinimum = False
Legend.Visible = False
View3D = False
Align = alTop
TabOrder = 0
Anchors = [akLeft, akTop, akRight, akBottom]
object Series1: THorizBarSeries
Marks.ArrowLength = 20
Marks.Visible = True
SeriesColor = clGreen
BarWidthPercent = 100
XValues.DateTime = False
XValues.Name = 'Bar'
XValues.Multiplier = 1.000000000000000000
XValues.Order = loNone
YValues.DateTime = False
YValues.Name = 'Y'
YValues.Multiplier = 1.000000000000000000
YValues.Order = loNone
end
end
object ResetBtn: TButton
Left = 488
Top = 432
Width = 75
Height = 25
Anchors = [akRight, akBottom]
Caption = 'Reset'
TabOrder = 1
OnClick = ResetBtnClick
end
end
Пойдет?