Added: TDateTimeEdit, TLabeledDateTimeEdit

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2016 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jujibo
2011-09-26 11:16:06 +00:00
parent 26fd1a86b9
commit 30d568fab9
8 changed files with 506 additions and 7 deletions

View File

@ -5,6 +5,7 @@ Note: Lazarus Trunk required
Version pre-1.0
--------------------------------------------------
2011-09-26 Added: TDateTimeEdit, TLabeledDateTimeEdit
2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit,
TJDBTimeEdit, TJDBLabeledTimeEdit
2011-09-22 Added: ftTime support

View File

@ -18,7 +18,7 @@
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="20">
<Files Count="22">
<Item1>
<Filename Value="src/jdbintegeredit.pas"/>
<HasRegisterProc Value="True"/>
@ -117,6 +117,16 @@
<HasRegisterProc Value="True"/>
<UnitName Value="JDBLabeledTimeEdit"/>
</Item20>
<Item21>
<Filename Value="src/jdatetimeedit.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="JDateTimeEdit"/>
</Item21>
<Item22>
<Filename Value="src/jlabeleddatetimeedit.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="JLabeledDateTimeEdit"/>
</Item22>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="2">

View File

@ -11,8 +11,8 @@ uses
jdblabeledcurrencyedit, jdbdateedit, jdblabeleddateedit, jcontrolutils,
JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit,
JDateEdit, JLabeledDateEdit, JDBGridControl, jdbgridutils, JDBLabeledEdit,
JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit,
LazarusPackageIntf;
JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit, JDateTimeEdit,
JLabeledDateTimeEdit, LazarusPackageIntf;
implementation
@ -36,6 +36,8 @@ begin
RegisterUnit('JLabeledTimeEdit', @JLabeledTimeEdit.Register);
RegisterUnit('JDBTimeEdit', @JDBTimeEdit.Register);
RegisterUnit('JDBLabeledTimeEdit', @JDBLabeledTimeEdit.Register);
RegisterUnit('JDateTimeEdit', @JDateTimeEdit.Register);
RegisterUnit('JLabeledDateTimeEdit', @JLabeledDateTimeEdit.Register);
end;
initialization

View File

@ -35,6 +35,7 @@ function NormalizeDateTime(const Value: string; theValue: TDateTime;
function NormalizeDateSeparator(const s: string): string;
function IsValidDateString(const Value: string): boolean;
function IsValidTimeString(const Value: string): boolean;
function IsValidDateTimeString(const Value: string): boolean;
implementation
@ -211,6 +212,7 @@ begin
else
theDateTime := theValue;
Result := '';
tokens := TStringList.Create;
Split(' ', Value, tokens);
if tokens.Count > 1 then
begin
@ -237,11 +239,14 @@ begin
end;
function IsValidDateString(const Value: string): boolean;
var
bTime: TDateTime;
begin
if StrToDateDef(Value, MaxDateTime) = MaxDateTime then
Result := False
else
Result := True;
//if StrToDateDef(Value, MaxDateTime) = MaxDateTime then
// Result := False
//else
// Result := True;
Result:= TryStrToDate(Value, bTime);
end;
function IsValidTimeString(const Value: string): boolean;
@ -251,5 +256,12 @@ begin
Result := TryStrToTime(Value, bTime);
end;
function IsValidDateTimeString(const Value: string): boolean;
var
bTime: TDateTime;
begin
Result := TryStrToDateTime(Value, bTime);
end;
end.

View File

@ -0,0 +1,191 @@
unit JDateTimeEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Graphics,
Dialogs, jcontrolutils;
type
TJDateTimeEdit = class(TCustomEdit)
private
{ Private declarations }
theValue: TDateTime;
fFormat: string;
function getFormat: string;
function getValue: TDateTime;
procedure formatInput;
procedure setFormat(const AValue: string);
procedure setValue(const AValue: TDateTime);
protected
{ Protected declarations }
procedure DoEnter; override;
procedure DoExit; override;
procedure KeyPress(var Key: char); override;
public
{ Public declarations }
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
function isNull: boolean;
property DisplayFormat: string read getFormat write setFormat;
property Value: TDateTime read getValue write setValue;
property Action;
property Align;
property Alignment;
property Anchors;
property AutoSize;
property AutoSelect;
property BidiMode;
property BorderStyle;
property BorderSpacing;
property CharCase;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property ParentBidiMode;
property OnChange;
property OnChangeBounds;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditingDone;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDrag;
property OnUTF8KeyPress;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabStop;
property TabOrder;
property Visible;
end;
procedure Register;
implementation
procedure Register;
begin
{$I jdatetimeedit_icon.lrs}
RegisterComponents('Additional', [TJDateTimeEdit]);
end;
function TJDateTimeEdit.getFormat: string;
begin
Result := fFormat;
end;
function TJDateTimeEdit.getValue: TDateTime;
begin
Result := theValue;
end;
procedure TJDateTimeEdit.formatInput;
begin
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue);
end;
procedure TJDateTimeEdit.setFormat(const AValue: string);
begin
fFormat := AValue;
formatInput;
end;
procedure TJDateTimeEdit.setValue(const AValue: TDateTime);
begin
theValue := AValue;
formatInput;
end;
procedure TJDateTimeEdit.DoEnter;
begin
inherited DoEnter;
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue)
else
Text := '';
SelectAll;
end;
procedure TJDateTimeEdit.DoExit;
var
bufText: string;
begin
inherited DoExit;
bufText := Text;
Text := NormalizeDateTime(Text, theValue);
if (Length(bufText) > 0) and (Length(Text) = 0) then
begin
ShowMessage(bufText + ' no es una fecha-hora válida');
SetFocus;
end
else
if Length(Text) = 0 then
theValue := 0
else
if IsValidDateTimeString(Text) then
theValue := StrToDateTime(Text)
else
begin
ShowMessage(Text + ' no es una fecha-hora válida');
SetFocus;
end;
formatInput;
end;
procedure TJDateTimeEdit.KeyPress(var Key: char);
begin
if not (Key in ['0'..'9', #8, #9, '.', '-', '/', ',', ':', ' ']) then
Key := #0;
inherited KeyPress(Key);
end;
constructor TJDateTimeEdit.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Text := '';
fFormat := ShortDateFormat + ' ' + ShortTimeFormat;
theValue := 0;
formatInput;
end;
destructor TJDateTimeEdit.Destroy;
begin
inherited Destroy;
end;
function TJDateTimeEdit.isNull: boolean;
begin
Result := theValue = 0;
end;
end.

View File

@ -0,0 +1,44 @@
LazarusResources.Add('tjdatetimeedit','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
+#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147
+#0#0#0#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#219#9#23#8
+'-(o'#127#232#182#0#0#3'wIDATH'#199#181#150']L'#155'U'#24#199#127'o?VZ'#218
+#210'v'#2'1'#142#175'1'#162#27'e'#26' '#11'n'#160#4#22']'#252#136#212#204#197
+#196#27#227#212#152',*'#243#2#146#145'x'#179#16'G'#184#217'4'#241'f'#238'b3$'
+'SI'#26'"'#222'll'#131#173#197#10#232#134','#19'Cdk'#7#140#149'Z'#218#173#165
+#244#243'xaJZ(['#193#248'KN'#206#155#243#156#243#255'?'#239#249'x'#207'+'#9
+'!'#216'('#131#223'u7'#169#228#129#14'UN'#228'9'#185'R'#174#139#199#4#161'`'
+#200#27#12#224#8#197#212']o|'#216#249's'#178#175#148'jp'#254#218'=N'#247'Og'
+#20#253#224#181#237#188#221#240'$'#215'~'#248#226'k'#131#225#193'acI'#203#22
+#149'>'#31#149#198#136#16#9#2#190'9'#188'3'#183#152#155#188#18#244'?Tv'#29'j'
+#253#234#248#138'A'#170#240#169'#'#207'b.'#214'r'#211#21#192#237#11#227#246
+'Gp'#251#194#244#217'f'#249#188'z'#232#212#182#29#166'OL%'#175#176#176#164'c'
+#226'/?'#238#197'%bq'#129'Q'#151'Ce'#185#22#163#152#230#143#171#231#184#239
+#142#181#189'{'#236't'#183'$'#132#160#185#221#206#238#10#19'e'#133'j'#204'%:'
+#10#12#170'4q'#183'?'#194#11'X'#235#183#26'<'#151'K'#247#28'Q'#222#154'S'#225
+#241#133#217#189#195#132'A/C '#225#245#199#25#153'\@'#171#146#177'S'#255'''c'
+#253'g'#151'BrS'#189#12'`{'#145#158#223#167#188#244#217'f'#211'D'#147'up9'
+#142'<'#177'x,o['#179'r!'#164'g'#222#187#140#165#177#20#147'N'#224#13#4#208
+#234's).'#210#211#178#191#156#251#15#19'xd'#187'(,{J'#19'_Z'#252'Ljo'#255'r'
+#227#171#156'B'#241#211':'#14#190'iA'#157#147#195#197#161'a'#242#203#170#249
+#229'W'''#7#202'''q'#244'}'#127'G'#1#208#218'j'#217#148#248#201#147'Vf\..^'
+#30'bb'#252#6#205'/'#31#192'X'#160#225#158'w'#153#188#186'R'#228'H'#133#138
+#213#3#178'!5'#161'\'#173#150#137#241#27#188#218'ba'#167#185#10#167'?J4'#154
+'@$"'#136#132'@'#177#222#192'l'#169#174#173#227#153'*3'#154'<='#129'0'#220
+#157#15#162#207#149#177'8;'#206'r,'#238'Q'#172#30'`'#233#156#2#192#218'Q'#177
+#166'-Ij'#172#190'a/H'#16'O'#128'<'#7'F'#175#187'y'#177'R'#134#243#183'a'#162
+'B'#225'Pd'#18#207#196#193#198#18#222#217#183'eM'#187#20#142#130#0#151';H'
+#191'c'#158'b'#181#135#252#208#21#134#167'CH'#234#173#221#138#213#153#245#216
+'#'#244#14':'#215#8#245#14':'#233#29'L'#207#30#224#248'7'#163#196#19#2#157#6
+#158#223'%x"|'#129#145#11'#T6'#30#162#241#245#247'F'#21#217#204'sR'#180#199
+#30#193#210'9'#149'f'#242#209#254#219' b'#252'=3'#197#29#199'Mn{'#148'T5'#29
+#198#188#167#14#0'Y6'#6'='#246#200#186#177#129'sV'#6#190#253#145#129#190#235
+'h'#10#26#176#142#204#179#247#165#183'V'#226'Y'#189#193#191'SV'#146'1v>q'#148
+'K]'#251#0#168#173#173'ell,-'#190#238'"'#167#238'&kGE'#198#221#149#13#138#245
+#182#223'z'#235#176#154'd'#246#143'4'#200#246#4'g'#162#185#221#254'H'#19#197
+#137#19#31'KCWm'#155#254#224#141#254#244#152#14'B'#136'5'#229#204#153#179#226
+#232#167#239#11'!'#132'hj'#179#137'h,.'#154#218'l+%'#217#158'|'#22'B'#136#154
+#154#154#180#218#191#232#18'B'#136#199#27'l'#150#164#129#148#233#210#127#224
+#187#251#159#238#136'$zC'#145'$m'#230#175'b#'#200#248#159#249#7'P'#175#19'N'
+#224#160'"'#1#0#0#0#0'IEND'#174'B`'#130
]);

View File

@ -0,0 +1,189 @@
unit JLabeledDateTimeEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, LResources, Controls, ExtCtrls, LCLType, Dialogs,
SysUtils;
type
TJLabeledDateTimeEdit = class(TCustomLabeledEdit)
private
{ Private declarations }
theValue: TDateTime;
fFormat: string;
function getFormat: string;
function getValue: TDateTime;
procedure formatInput;
procedure setFormat(const AValue: string);
procedure setValue(const AValue: TDateTime);
protected
{ Protected declarations }
procedure DoEnter; override;
procedure DoExit; override;
procedure KeyPress(var Key: char); override;
public
{ Public declarations }
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
function isNull: boolean;
property DisplayFormat: string read getFormat write setFormat;
property Value: TDateTime read getValue write setValue;
property Action;
property Align;
property Alignment;
property Anchors;
property AutoSelect;
property AutoSize;
property BidiMode;
property BorderSpacing;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property DragCursor;
property DragMode;
property EditLabel;
property Enabled;
property Font;
property LabelPosition;
property LabelSpacing;
property MaxLength;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditingDone;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property OnUTF8KeyPress;
end;
procedure Register;
implementation
uses
jcontrolutils;
procedure Register;
begin
{$I jlabeleddatetimeedit_icon.lrs}
RegisterComponents('Additional',[TJLabeledDateTimeEdit]);
end;
function TJLabeledDateTimeEdit.getFormat: string;
begin
Result := fFormat;
end;
function TJLabeledDateTimeEdit.getValue: TDateTime;
begin
Result := theValue;
end;
procedure TJLabeledDateTimeEdit.formatInput;
begin
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue);
end;
procedure TJLabeledDateTimeEdit.setFormat(const AValue: string);
begin
fFormat := AValue;
formatInput;
end;
procedure TJLabeledDateTimeEdit.setValue(const AValue: TDateTime);
begin
theValue := AValue;
formatInput;
end;
procedure TJLabeledDateTimeEdit.DoEnter;
begin
inherited DoEnter;
if theValue <> 0 then
Text := FormatDateTime(DisplayFormat, theValue)
else
Text := '';
SelectAll;
end;
procedure TJLabeledDateTimeEdit.DoExit;
var
bufText: string;
begin
inherited DoExit;
bufText := Text;
Text := NormalizeDateTime(Text, theValue);
if (Length(bufText) > 0) and (Length(Text) = 0) then
begin
ShowMessage(bufText + ' no es una fecha-hora válida');
SetFocus;
end
else
if Length(Text) = 0 then
theValue := 0
else
if IsValidDateTimeString(Text) then
theValue := StrToDateTime(Text)
else
begin
ShowMessage(Text + ' no es una fecha-hora válida');
SetFocus;
end;
formatInput;
end;
procedure TJLabeledDateTimeEdit.KeyPress(var Key: char);
begin
if not (Key in ['0'..'9', #8, #9, '.', '-', '/', ',', ':', ' ']) then
Key := #0;
inherited KeyPress(Key);
end;
constructor TJLabeledDateTimeEdit.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Text := '';
fFormat := ShortDateFormat + ' ' + ShortTimeFormat;
theValue := 0;
formatInput;
end;
destructor TJLabeledDateTimeEdit.Destroy;
begin
inherited Destroy;
end;
function TJLabeledDateTimeEdit.isNull: boolean;
begin
Result := theValue = 0;
end;
end.

View File

@ -0,0 +1,50 @@
LazarusResources.Add('TJLabeledDateTimeEdit','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
+#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147
+#0#0#0#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#219#9#26#11
+#2#8#182'!'#150#151#0#0#3#245'IDATH'#199#213#148'mL[U'#28#198#127'--'#165'@'
+#11'-'#140#133#205'Q7'#4'",l'#142#142#8#211#141#177#206' '#18#5#227'K'#140'1'
+'$'#186'e'#137'&'#147'e'#17'R'#249#226'+7l'#209#160'1~'#209'E1!'#190'dI'#197
+'@'#156#163#19#198#138'0'#214'm'#178#225'd'#193'M'#25#3'G'#135#5#182#150#210
+#215#227#7'VB'#1#23#182'D'#19#159#228#230#254#207#185#231'>'#191'{'#206's'
+#206#149'q'#151'j'#255#234'@'#177'*'#202'U'#171#138#241'm'#140'RFi'#130#1#129
+#199#237'q'#186']'#244'x'#2#234#250#242'=u'#221#0#178#249'/}'#217'9'#202'''-'
+#151#151'4'#220']'#182#142#231#182#174#2#160#243#155#186#143#19#19'o'#188#164
+'3'#148'G'#171#180'+P'#197#234#16'"'#132'kr'#20#231#213#11#140#14#180#187#167
+'n*'#235#159#221#247#209#219#178#133#198#31#188#178#129#245'i'#241#244'_q'
+#225#152#244#226#152#242#225#152#244#210'l'#27#1'`'#255#195#14#145#149':'#134
+#222'P'#202#245'i'#13#231'/M'#225#152#152'&'#16#20#232'41'#228#164#199#163#19
+#151#249#181#243#11#198#28#129'j'#25'@q'#181#141#220#12'=kW'#170'Yo'#208#144
+#146#168#138'0wL'#249'p'#207#4#137#241';'#168'X'#221'*'#210#31'|'#153#11#163
+'*'#198''''#189#228#222#167'''Q+G '#195'9'#21#164'w'#224':'#241'*9'#247'k/bo'
+'i'#156#150#3#172'['#163#229#220#160#147'f'#219'H'#132#233'|'#243's'#131'N'
+#214#134'N'#11'}Z1'#215'=Z'#174'9g'#168'('#186#23#189'F'#224't'#185#136#215
+#198#145#182'FK'#185')'#157#177#155'!'#198#229#217#172'\'#187':V'#1#144't'
+#181'C$'#221'J'#227#231#214'3'#0'X'#173#141#152'L'#149#0#168#128#205'2HS'#15
+#19#167#127#132#31#7#156'l'#202'Na: P*'#149#180#253'`'#225#169'''+('#221#177
+#131#215#235#14#146#157#185#137#238#211'C'#148'd'#230#207#134'\S'#243#161#168
+#170#170#152#11#180#172#172'|'#174'ni'#249#150#174#174#147'H'#146#4#128#217
+'l'#230#178'7'#131#175#223#127#145#182#174'^'#226'Tr'#10#141#198#136#13#241
+#249#177'n>k:KU)'#200#23#238#150#134#6#203#220#151#155'L'#149'44X'#144'$'#9
+#147#169#146#183'voF'#146'$<'#190#16'f'#179#153#157'['#242')4'#26'1'#155#205
+#152#202#30#7#224'H'#143#29'o'#0#252#254#16'"4'#131'b! <'#19#171#181'1'#162
+#182'Z'#27#177#222#26#147#16'''g'#197#6#19'0;'#171#216#228'T'#246#236#221#137
+#181#229';\>'#24#190#230'F'#27'''gb'#164'o1'#0#160#226#221#193'E}'#202#130
+#131#20'%'#216'('#201#157'&:K'#205'h'#159'u'#238#217#244#248#159'$'#235#10#1
+#136#143#129'Sg'#29'l'#203#145'3t'#230#167#197'K4'#223'<'#156#133#217'l'#198
+#223#253#26'mG'#154#217#127#160#13#189#191#7'I'#146'x'#166#166#137'O'#15'['
+#145'$'#9#153#199#15'@I'#190#145'4'#181#131#21#158#239#25#190#228#158'Y2'#228
+#166'.'#31#135';'#134#176#212'f,'#2#231#170#251')J:'#193#198#162#237#140#201
+#243#233#254'%'#192#228#205' '#193#144'@'#19#11#5#217#130'd'#239'QN'#29#237
+#197'C'#210#155#138#229#254'{'#194#176#166'.'#3#237#221#1'<'#173#29'$'#175
+#178'Q'#146#153'Cb'#170#1'D'#128#191#174#14#242'GO?'#191#143'+'#201'*|'#154
+#237'O'#236'zc'#217#128#166'.'#31#207'o'#137#6#224#188'w#U/'#20'p'#209'~'#140
+#227#173'}'#168#21'v'#252'~?'#241#186#20#250'~'#155#161#230#157#247#136#213
+#204#142']6'#224'p'#199#16'`'#152'k'#235'W'#222'C'#193'c'#149#156#28#180#240
+'h'#233#3'l'#219#250#16'F'#163#17#187#221#14#192#141#201#225#165#1#243'C'#14
+#215#150#218#12','#181#25#17#237#229'J'#241'Ok}'#187#28#238'D'#138#249''''
+#248#223#144#2#160#190'~'#175#172#227#248#9#193#127#165'C'#135#26#197#190'Ww'
+#9'!'#132'('#174#182#9#127' ('#138#171'msW'#184'?\'#11'!D^^^'#196'}j'#226#138
+'X'#22#224'n'#21#6#200#150#2#220#150'~'#7'J'#208#165#201#248#223#235'o'#178
+'%'#28#178#184#185#181#224#0#0#0#0'IEND'#174'B`'#130
]);