Added: AllowNull property to TJLabeledIntegerEdit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2851 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jujibo
2013-11-27 10:01:09 +00:00
parent b2b2c69c87
commit eda11d6bf8

View File

@ -31,6 +31,7 @@ type
TJLabeledIntegerEdit = class(TCustomLabeledEdit) TJLabeledIntegerEdit = class(TCustomLabeledEdit)
private private
fNull: boolean;
{ Private declarations } { Private declarations }
theValue: integer; theValue: integer;
fFormat: string; fFormat: string;
@ -50,11 +51,13 @@ type
{ Public declarations } { Public declarations }
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
function isNull: boolean;
property CurrentValue: integer read getCurrentValue; property CurrentValue: integer read getCurrentValue;
published published
{ Published declarations } { Published declarations }
property DisplayFormat: string read getFormat write setFormat; property DisplayFormat: string read getFormat write setFormat;
property Value: integer read getValue write setValue; property Value: integer read getValue write setValue;
property AllowNull: boolean read fNull write fNull default False;
property Action; property Action;
property Align; property Align;
@ -154,7 +157,8 @@ end;
procedure TJLabeledIntegerEdit.FormatInput; procedure TJLabeledIntegerEdit.FormatInput;
begin begin
Text := FormatFloat(fFormat, theValue); if not fNull then
Text := FormatFloat(fFormat, theValue);
end; end;
procedure TJLabeledIntegerEdit.DoEnter; procedure TJLabeledIntegerEdit.DoEnter;
@ -162,7 +166,8 @@ begin
inherited DoEnter; inherited DoEnter;
if ReadOnly then if ReadOnly then
exit; exit;
Text := IntToStr(theValue); if not fNull then
Text := IntToStr(theValue);
SelectAll; SelectAll;
end; end;
@ -171,6 +176,9 @@ begin
inherited DoExit; inherited DoExit;
if ReadOnly then if ReadOnly then
exit; exit;
if fNull and (Length(Caption) = 0) then
theValue:= Low(Integer) // min integer value means null
else
if IsValidInteger(Text) then if IsValidInteger(Text) then
theValue := StrToInt(Text) theValue := StrToInt(Text)
else else
@ -202,5 +210,10 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TJLabeledIntegerEdit.isNull: boolean;
begin
Result:= theValue = Low(Integer);
end;
end. end.