also ich würde das ganze so lösen:
Delphi-Quellcode:
TIntEdit = class(TEdit)
private
fAllowed: String;
fNewOnChange: TNotifyEvent;
fNewOnKeyPress: TKeyPressEvent;
function fGetText: String;
procedure fSetText(AValue: String);
procedure fOnKeyPressproc(Sender: TObject; var Key: Char);
procedure fOnChangeProc(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
published
property Text: String read fGetText write fSetText;
property OnChange: TNotifyEvent read fNewOnChange write fNewOnChange;
property OnKeyPress: TKeyPressEvent read fNewOnKeyPress write fNewOnKeyPress;
end;
[...]
constructor TIntEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fAllowed := '0123456789';
inherited OnKeyPress := fOnKeyPressproc;
inherited OnChange := fOnChangeProc;
end;
function TIntEdit.fGetText: String;
begin
result := inherited Text;
end;
procedure TIntEdit.fSetText(AValue: String);
var LCount: Integer;
begin
for LCount := 1 to length(AValue) do
begin
if pos(AValue[LCount], fAllowed) > 0 then Exit;
end;
inherited Text := AValue;
end;
procedure TIntEdit.fOnKeyPressproc(Sender: TObject; var Key: Char);
begin
if pos(key, fAllowed) < 1 then
key := #0
else if Assigned(fNewOnKeyPress) then fNewOnKeyPress(Sender, Key);
end;
procedure TIntEdit.fOnChangeProc(Sender: TObject);
var LCount: Integer;
Lnew: String;
begin
LNew := '';
for LCount := 1 to length(Text) do
begin
if pos(Text[LCount], fAllowed) > 0 then
LNew := LNew + Text[LCount];
end;
if LNew <> Text then Text := LNew;
if Assigned(fNewOnChange) then fNewOnChange(Sender);
end;
Wobei diese Variante kein "Strg + V" mehr zulässt