كود لانشاء مكون نص Edit لايقبل الا ارقام
كود:
Type
TNumEdit=class(TCustomEdit)
private
FInputError:TNotifyevent;
Protected
Function GetValue:integer;
Procedure SetValue(Value:Integer);
Procedure KeyPress(var Key:char);override;
Public
Constructor Create(Owner:TComponent);override;
Published
Property OnInputError:TNotifyEvent read FInputError write FInputError;
Property Value:integer read GetValue write SetValue Default 0;
Property AutoSelect;
Property AutoSize;
//.....and so on
end;
//------------------------------------------
Function TNumEdit.GetValue:integer;
begin
Result:=StrToIntDef(Text,0);
End;
//------------------------------------------
Procedure TNumEdit.SetValue(Value:Integer);
Begin
text:=IntToStr(Value);
End;
//------------------------------------------
Procedure TNumEdit.KeyPress(var Key:char);
Begin
If Not(Key in ['0'..'9']) And Not(Key=#8) Then
Begin
Key:=#0;//Null
If Assigned(FInputError) Then
FInputError(Self);
End
else
Inherited;
End;
//------------------------------------------
الصدر الفريق العربى للبرمجة