Implement EditFormat in all nondb components except timeedit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4551 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jujibo
2016-03-14 09:35:30 +00:00
parent ca00c9c90c
commit bfcc831505
4 changed files with 48 additions and 28 deletions

View File

@ -31,6 +31,7 @@ type
TJLabeledCurrencyEdit = class(TCustomLabeledEdit)
private
fEFormat: string;
theValue: currency;
fFormat: string;
fDecimals: integer;
@ -55,6 +56,7 @@ type
published
{ Published declarations }
property DisplayFormat: string read getFormat write setFormat;
property EditFormat: string read fEFormat write fEFormat;
property Decimals: integer read getDecimals write setDecimals;
property Value: currency read getValue write setValue;
@ -182,6 +184,9 @@ begin
inherited DoEnter;
if ReadOnly then
exit;
if EditFormat <> '' then
Text := FormatFloat(EditFormat, theValue)
else
Text := FloatToStr(theValue);
SelectAll;
end;

View File

@ -31,15 +31,16 @@ type
TJLabeledDateEdit = class(TCustomLabeledEdit)
private
fEFormat: string;
theValue: TDateTime;
fFormat: string;
FButton: TSpeedButton;
FButtonNeedsFocus: Boolean;
function GetButtonWidth: Integer;
FButtonNeedsFocus: boolean;
function GetButtonWidth: integer;
function getFormat: string;
function getValue: TDateTime;
procedure formatInput;
procedure SetButtonWidth(AValue: Integer);
procedure SetButtonWidth(AValue: integer);
procedure setFormat(const AValue: string);
procedure setValue(const AValue: TDateTime);
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
@ -48,7 +49,7 @@ type
{ Protected declarations }
procedure DoEnter; override;
procedure DoExit; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyDown(var Key: word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override;
procedure SetParent(AParent: TWinControl); override;
procedure DoPositionButton; virtual;
@ -68,9 +69,10 @@ type
{ Published declarations }
function isNull: boolean;
property DisplayFormat: string read getFormat write setFormat;
property EditFormat: string read fEFormat write fEFormat;
property Value: TDateTime read getValue write setValue;
property Button: TSpeedButton read FButton;
property ButtonWidth : Integer read GetButtonWidth write SetButtonWidth;
property ButtonWidth: integer read GetButtonWidth write SetButtonWidth;
property Action;
property Align;
@ -137,7 +139,7 @@ begin
Result := fFormat;
end;
function TJLabeledDateEdit.GetButtonWidth: Integer;
function TJLabeledDateEdit.GetButtonWidth: integer;
begin
Result := FButton.Width;
end;
@ -155,7 +157,7 @@ begin
Text := '';
end;
procedure TJLabeledDateEdit.SetButtonWidth(AValue: Integer);
procedure TJLabeledDateEdit.SetButtonWidth(AValue: integer);
begin
FButton.Width := AValue;
end;
@ -190,7 +192,12 @@ begin
if ReadOnly then
exit;
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue)
begin
if EditFormat <> '' then
Text := FormatDateTime(EditFormat, theValue)
else
Text := FormatDateTime(DefaultFormatSettings.ShortDateFormat, theValue);
end
else
Text := '';
SelectAll;
@ -215,7 +222,7 @@ begin
formatInput;
end;
procedure TJLabeledDateEdit.KeyDown(var Key: Word; Shift: TShiftState);
procedure TJLabeledDateEdit.KeyDown(var Key: word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if (ssAlt in Shift) and (key = 40) then
@ -241,7 +248,8 @@ end;
procedure TJLabeledDateEdit.DoPositionButton;
begin
if FButton = nil then exit;
if FButton = nil then
exit;
FButton.Parent := Parent;
FButton.Visible := True;
if BiDiMode = bdLeftToRight then
@ -252,12 +260,11 @@ end;
procedure TJLabeledDateEdit.CheckButtonVisible;
begin
If Assigned(FButton) then
if Assigned(FButton) then
FButton.Visible := True;
end;
procedure TJLabeledDateEdit.Notification(AComponent: TComponent;
Operation: TOperation);
procedure TJLabeledDateEdit.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = FButton) and (Operation = opRemove) then

View File

@ -33,6 +33,7 @@ type
TJLabeledDateTimeEdit = class(TCustomLabeledEdit)
private
fEFormat: string;
{ Private declarations }
theValue: TDateTime;
fFormat: string;
@ -72,6 +73,7 @@ type
{ Published declarations }
function isNull: boolean;
property DisplayFormat: string read getFormat write setFormat;
property EditFormat: string read fEFormat write fEFormat;
property Value: TDateTime read getValue write setValue;
property Button: TSpeedButton read FButton;
property ButtonWidth: integer read GetButtonWidth write SetButtonWidth;
@ -195,7 +197,13 @@ begin
if ReadOnly then
exit;
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue)
begin
if EditFormat <> '' then
Text := FormatDateTime(EditFormat, theValue)
else
Text := FormatDateTime(DefaultFormatSettings.ShortDateFormat +
' ' + DefaultFormatSettings.ShortTimeFormat, theValue);
end
else
Text := '';
SelectAll;

View File

@ -189,7 +189,7 @@ begin
inherited DoEnter;
if ReadOnly then
exit;
if Length(EditFormat) > 0 then
if EditFormat <> '' then
Text := FormatFloat(EditFormat, theValue)
else
Text := FloatToStr(theValue);