home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 11
/
Freelog011.iso
/
BestOf
/
PhoenixMail
/
Source
/
comps
/
NumEdit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-02-10
|
3KB
|
127 lines
{*****************************************************************************
*
* NumEdit.pas - TNumEdit Component
*
* Copyright (c) 1998-99 Michael Haller
*
* Author: Michael Haller
* E-mail: michael@discountdrive.com
* Homepage: http://www.discountdrive.com/sunrise/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
*----------------------------------------------------------------------------
*
* Revision history:
*
* DATE REV DESCRIPTION
* ----------- --- ----------------------------------------------------------
*
*****************************************************************************}
unit NumEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TNumEdit = class(TEdit)
private
FMin: Integer;
FMax: Integer;
FValue: Integer;
procedure MakeValidText;
function GetValue: Integer;
procedure SetValue(I: Integer);
protected
procedure KeyPress(var Key: Char); override;
procedure WndProc(var Message: TMessage); override;
public
constructor Create(AOwner: TComponent); override;
published
property Min: Integer read FMin write FMin;
property Max: Integer read FMax write FMax;
property Value: Integer read GetValue write SetValue;
end;
procedure Register;
implementation
procedure TNumEdit.MakeValidText;
var
I: LongInt;
begin
I := FMin;
try
if Text = '' then I := 0 else I := StrToInt(Text);
if I > FMax then I := FMax;
if I < FMin then I := FMin;
finally
Text := IntToStr(I);
end;
end;
function TNumEdit.GetValue: Integer;
begin
Result := 0;
if (Text <> '') and (Text <> '-') then begin
try
Result := StrToInt(Text);
except end;
end;
FValue := Result;
end;
procedure TNumEdit.SetValue(I: Integer);
begin
try
Text := IntToStr(I);
except end;
FValue := StrToInt(Text);
end;
procedure TNumEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if Key in ['0'..'9', #8, '-'] = False then Key := Chr(0);
end;
procedure TNumEdit.WndProc(var Message: TMessage);
begin
inherited WndProc(Message);
if Message.Msg = WM_KILLFOCUS then MakeValidText;
end;
constructor TNumEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMin := 0;
FMax := 100;
AutoSize := False;
Height := 17;
MaxLength := 5;
Text := '0';
end;
procedure Register;
begin
RegisterComponents('Michael Haller', [TNumEdit]);
end;
end.