اصلاح کارکترهای "ک"درزمان ورود.
با سلام
دوستان بنده یک فرم Master ساختم وKeyPreview مربوط به فرم را True کرده ام و در رویداد KeyPress مربوط به آن کد زیر را نوشته ام.
procedure TMaster.MyEdit2KeyPress(Sender: TObject; var Key: Char);
begin
IF Key = #223 then Key := #152;
IF Key = #236 then Key := #237;
end;
حالا همه فرمهای را از کلاس این فرم می سازم.
TForm1 = class(TMaster)
حالا هر زمان کاربر کلید"ک" را بزند و کد مربوط #223 باشد به #152 تغییر میکند.
و اگر کلید "ی" با کد #236 زده بشود به #237 تبدیل می شود.
حالا بنده دو سوال داشتم.
1-نظر شما دوستان در رابطه با این کار چی است؟خوب است یا بد و همچنین دلیل خود را بیان کنید.
2-اگر روشی بهتر و سریععتر از این داریدپیشنهاد کنید.
منتظر نظرات شما دوستان محترم هستم.
یک تغییر کوچیک در کامپوننت آقای کرامتی
unit uFarsiFixer;
interface
uses
Forms,
Controls,
SysUtils,
Dialogs,
Classes;
type
TFarsiKeyboardHook = class(TComponent)
private
parentKeyPress: TKeyPressEvent;
procedure myKeyPress(Sender: TObject; var Key: Char);
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Barnamenevis.org', [TFarsiKeyboardHook]);
end;
{ TFarsiKeyboardHook }
constructor TFarsiKeyboardHook.Create(AOwner: TComponent);
begin
inherited;
if AOwner is TForm then
begin
parentKeyPress := TForm(Owner).OnKeyPress;
TForm(Owner).OnKeyPress := myKeyPress;
TForm(Owner).KeyPreview := True;
end;
end;
procedure TFarsiKeyboardHook.myKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #152 then Key := #223;
if Key = #236 then Key := #237;
if Assigned(parentKeyPress) then
parentKeyPress(Sender, Key);
end;
end.