You've already forked lazarus-ccr
Added: TJDBTimeEdit, TJDBLabeledTimeEdit
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1991 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -5,11 +5,12 @@ Note: Lazarus Trunk required
|
||||
|
||||
Version pre-1.0
|
||||
--------------------------------------------------
|
||||
2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit
|
||||
2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit,
|
||||
TJDBTimeEdit, TJDBLabeledTimeEdit
|
||||
2011-09-22 Added: ftTime support
|
||||
2011-09-21 Added: TJDBGridControl and example (testgridctr)
|
||||
2011-09-20 Added: TJIntegerEdit, TJLabeledIntegerEdit
|
||||
TJCurrencyEdit, TJLabeledCurrencyEdit
|
||||
2011-09-20 Added: TJIntegerEdit, TJLabeledIntegerEdit,
|
||||
TJCurrencyEdit, TJLabeledCurrencyEdit,
|
||||
TJDateEdit, TJLabeledDateEdit
|
||||
2011-09-19 Added: TJDBLabeledIntegerEdit, TJDBLabeledCurrencyEdit, TJDBLabeledDateEdit
|
||||
2011-09-19 First package: TJDBIntegerEdit, TJDBCurrencyEdit, TJDBDateEdit and example
|
||||
|
@ -18,7 +18,7 @@
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Files Count="18">
|
||||
<Files Count="20">
|
||||
<Item1>
|
||||
<Filename Value="src/jdbintegeredit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -107,6 +107,16 @@
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JLabeledTimeEdit"/>
|
||||
</Item18>
|
||||
<Item19>
|
||||
<Filename Value="src/jdbtimeedit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JDBTimeEdit"/>
|
||||
</Item19>
|
||||
<Item20>
|
||||
<Filename Value="src/jdblabeledtimeedit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JDBLabeledTimeEdit"/>
|
||||
</Item20>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="2">
|
||||
|
@ -11,7 +11,8 @@ uses
|
||||
jdblabeledcurrencyedit, jdbdateedit, jdblabeleddateedit, jcontrolutils,
|
||||
JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit,
|
||||
JDateEdit, JLabeledDateEdit, JDBGridControl, jdbgridutils, JDBLabeledEdit,
|
||||
JTimeEdit, JLabeledTimeEdit, LazarusPackageIntf;
|
||||
JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit,
|
||||
LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
@ -33,6 +34,8 @@ begin
|
||||
RegisterUnit('JDBLabeledEdit', @JDBLabeledEdit.Register);
|
||||
RegisterUnit('JTimeEdit', @JTimeEdit.Register);
|
||||
RegisterUnit('JLabeledTimeEdit', @JLabeledTimeEdit.Register);
|
||||
RegisterUnit('JDBTimeEdit', @JDBTimeEdit.Register);
|
||||
RegisterUnit('JDBLabeledTimeEdit', @JDBLabeledTimeEdit.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -52,8 +52,6 @@ type
|
||||
procedure SetDataSource(Value: TDataSource);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
|
||||
function IsValidCurrency(const Value: string): boolean;
|
||||
|
||||
protected
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
@ -262,14 +260,6 @@ begin
|
||||
Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility?
|
||||
end;
|
||||
|
||||
function TJDBDateEdit.IsValidCurrency(const Value: string): boolean;
|
||||
begin
|
||||
if StrToCurrDef(Value, MaxCurrency) = MaxCurrency then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJDBDateEdit.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
|
325
components/jujiboutils/jujibo-utils/src/jdblabeledtimeedit.pas
Normal file
325
components/jujiboutils/jujibo-utils/src/jdblabeledtimeedit.pas
Normal file
@ -0,0 +1,325 @@
|
||||
unit JDBLabeledTimeEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, LResources, Controls, ExtCtrls, DB, DBCtrls, LMessages, LCLType, Dialogs,
|
||||
SysUtils, jcontrolutils;
|
||||
|
||||
type
|
||||
TJDBLabeledTimeEdit = class(TCustomLabeledEdit)
|
||||
private
|
||||
{ Private declarations }
|
||||
fFormat: string;
|
||||
FDataLink: TFieldDataLink;
|
||||
|
||||
procedure DataChange(Sender: TObject);
|
||||
procedure UpdateData(Sender: TObject);
|
||||
procedure FocusRequest(Sender: TObject);
|
||||
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
|
||||
function IsReadOnly: boolean;
|
||||
|
||||
function getFormat: string;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure formatInput;
|
||||
|
||||
procedure SetDataField(const Value: string);
|
||||
procedure SetDataSource(Value: TDataSource);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
|
||||
protected
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure ActiveChange(Sender: TObject); virtual;
|
||||
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||
procedure KeyPress(var Key: char); override;
|
||||
procedure DoEnter; override;
|
||||
function GetReadOnly: boolean; override;
|
||||
procedure SetReadOnly(Value: boolean); override;
|
||||
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure EditingDone; override;
|
||||
property Field: TField read GetField;
|
||||
|
||||
published
|
||||
property DisplayFormat: string read getFormat write setFormat;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property ReadOnly: boolean read GetReadOnly write SetReadOnly default False;
|
||||
|
||||
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
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
{$I jdblabeledtimeedit_icon.lrs}
|
||||
RegisterComponents('Data Controls', [TJDBLabeledTimeEdit]);
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
begin
|
||||
if not Focused then
|
||||
formatInput
|
||||
else
|
||||
Caption := FDataLink.Field.AsString;
|
||||
end
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.UpdateData(Sender: TObject);
|
||||
var
|
||||
theValue: string;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
begin
|
||||
theValue := NormalizeTime(Text, FDataLink.Field.AsDateTime);
|
||||
if Text = '' then
|
||||
begin
|
||||
Field.DataSet.Edit;
|
||||
Field.Value := Null;
|
||||
end
|
||||
else
|
||||
if IsValidTimeString(theValue) then
|
||||
begin
|
||||
FDataLink.Field.Text := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowMessage(Caption + ' no es una hora válida');
|
||||
Caption := FDataLink.Field.AsString;
|
||||
SelectAll;
|
||||
SetFocus;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.FocusRequest(Sender: TObject);
|
||||
begin
|
||||
SetFocus;
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.IsReadOnly: boolean;
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
Result := not FDatalink.CanModify
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
if not Focused then
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.formatInput;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
if (fFormat <> '') and (not FDataLink.Field.IsNull) then
|
||||
Caption := FormatDateTime(fFormat, FDataLink.Field.AsDateTime)
|
||||
else
|
||||
Caption := FDataLink.Field.DisplayText
|
||||
else
|
||||
Caption := 'nil';
|
||||
end;
|
||||
|
||||
function TJDBLabeledTimeEdit.GetReadOnly: boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.SetReadOnly(Value: boolean);
|
||||
begin
|
||||
inherited;
|
||||
FDataLink.ReadOnly := Value;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.SetDataField(const Value: string);
|
||||
begin
|
||||
FDataLink.FieldName := Value;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.SetDataSource(Value: TDataSource);
|
||||
begin
|
||||
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
|
||||
ChangeDataSource(Self, FDataLink, Value);
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility?
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
// clean up
|
||||
if (Operation = opRemove) then
|
||||
begin
|
||||
if (FDataLink <> nil) and (AComponent = DataSource) then
|
||||
DataSource := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
datachange(Sender)
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.KeyDown(var Key: word; Shift: TShiftState);
|
||||
begin
|
||||
inherited KeyDown(Key, Shift);
|
||||
if Key = VK_ESCAPE then
|
||||
begin
|
||||
FDataLink.Reset;
|
||||
SelectAll;
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if Key in [VK_DELETE, VK_BACK] then
|
||||
begin
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit
|
||||
else
|
||||
Key := VK_UNKNOWN;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.KeyPress(var Key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, ':']) then
|
||||
Key := #0
|
||||
else
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.DoEnter;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
Caption := FDataLink.Field.AsString;
|
||||
inherited DoEnter;
|
||||
end;
|
||||
|
||||
constructor TJDBLabeledTimeEdit.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
ControlStyle := ControlStyle + [csReplicatable];
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLInk.OnActiveChange := @ActiveChange;
|
||||
// Set default values
|
||||
//fFormat := ShortDateFormat;
|
||||
end;
|
||||
|
||||
destructor TJDBLabeledTimeEdit.Destroy;
|
||||
begin
|
||||
FDataLink.Free;
|
||||
FDataLink := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TJDBLabeledTimeEdit.EditingDone;
|
||||
begin
|
||||
inherited EditingDone;
|
||||
UpdateData(self);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -0,0 +1,52 @@
|
||||
LazarusResources.Add('tjdblabeledtimeedit','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#14
|
||||
+#8')'#244#6'tu'#0#0#4'AIDATH'#199#213#149'_LSW'#28#199'?'#183#5#10'h'#161#165
|
||||
+#131'F7'#237#0#167'L'#17']'#236'p'#138'Q,'#198#17#5#3'L'#199#212'=0'#209'lq'
|
||||
+#203#156#206#192#140#238#193'Le'#232#148#145'-'#238'A%'#209'%'#211#233#22'A'
|
||||
+#153#219#156#192#130'EA'#171#137#138'N'#166#242'G'#133'i'#199'*'#229'_)'#180
|
||||
+#247#236#129'pSFc'#140'>'#237#251'r'#207#185#231#158#243#253#221#207#249#230
|
||||
+#28#137#167'P'#213#145#157#22#141#186'{'#179'&'#184#127#186':P'#173#245'z'#4
|
||||
+#174#30#151#163#167#155'Z'#151''''#164'0'#227#221#29#231#135#190#149'|'''#30
|
||||
+#174'n'#19#251#202#27#253'.'#186'&-'#134#229's'#199'J'#213'Gw'#236#213#233':'
|
||||
+'s'#245#166#140' MX$'#154'P=B'#200'tw'#180#225#184#127#131#182#155'U='#206
|
||||
+#174#192#194#236#245'_'#127#166#24#248'.\'#252#254'4'#226#199#143#166#254'n7'
|
||||
+#246#14'7vg?'#246#14'7e'#214'V^'#127#225'6o'#204'v'#17'aZ'#196#223#189'Z'#174
|
||||
+#221'qb'#127#212#139#199'+'#208'k'#131#153#18';'#26#189'h'#228#143#234'C<'
|
||||
+#180'{'#242#222#217#188#127#151#4'`'#201#179#138#132#151'"'#136'6'#134#16'o'
|
||||
+#210#18#165#211#144#147#149#204#198#162#147#138'I'#144#219'Nj'#212#9'bg'#174
|
||||
+#229'F'#155#134#246#14'7'#9#19'"'#208#133#169#16'H8'#156'^VdZ'#216#178#231#24
|
||||
+'/'#135'5`+?'#216#235'RG'#204'Q'#1#196#140#11#227#234'-'#7'e'#214'V'#236#206
|
||||
+'~r'#178#146#1#248'b}:vg?'#175#132'\'#227#196'7'#31#177'vk%'#191#159#189#196
|
||||
+#3'G'#31#219'7.%B+ptw'#147'j'#153#199#138'L'#11#0#219'6,'#163']5'#25'c'#244
|
||||
+#243#161#222#222'G'#27'$'#128#213'_]'#21'F'#157#134#168#240' '#202#172#173#0
|
||||
+'8+'#214#17#158'R'#172#180#183#173'['#192#180'yo'#147#158#149#195#183#165#149
|
||||
+#220#168#251#141#130#130#2#0'6m'#218#196#194#180'4'#230'''%Qt'#184#130#186'K'
|
||||
+'-'#164#198#222#164#182#236'h'#179#10#160#241'^'#167#178#153#155'W'#198'QQ'
|
||||
+#152#164#180#215#164#197#0#176#165#248#12#233'Y9'#0#24#12'!X'#210'2'#149'9}'
|
||||
+#170'@'#182#23#20#2#160#143#10#229'/G'#31#225#145'/'#162'F2*'#136'.\oW'#170
|
||||
+#247#167#173'k'#18#249#245#231#163','#249'`?n/T'#150#31'W'#198#130#229#1#22
|
||||
+'g'#12#26#186'=00 #'#228'>'#132',x,"'#128#240#148'b'#214'&>Pp'#0#236'9R'#193
|
||||
+#134#183'R('#173':'#207#181#203#23#249#244#227#15#249#169#206#198#226#153'f'
|
||||
+#0'R'#223#219#203#178'Iu'#212#156#172#188#167#164'h'#214#212'H'#162#194#131
|
||||
+#136'7i'#177'$'#24'F'#196'Tj'#252#145#132'1'#237#4#197#173#162#186'A'#144#187
|
||||
+'t"j'#15#4#168#7#195#238#149#193'#A'#209'w'#127'2/'#182#147#190#203#187'ij'
|
||||
+#246#28#11#240'E'#228#149#5#241#166'8JJ'#14#13#195'3'#26' 8'#148#150#134#22
|
||||
+'f'#198#214'2N;'#133#146#31#26'X'#248#170#145#9#198'Q '#224#174#189#135#242
|
||||
+#218#7#140#15'i'''#210'U'#197#185'F'#23'R'#136'a'#151'_D+'''#221#161#254#234
|
||||
+#217#17#251'`'#8#150#137#209'w1=y>'#15'U'#137#156#191#238#161#163#203#139'W'
|
||||
+#22'hCa'#214'd'#193's'#238#211'\<}'#129'IIo2'#127'I'#174#20#0#208#210#218#133
|
||||
+'Q'#167'Q'#146#211'l'#187'3'#200#250#203'}#LlU'#165#212#158#250#30#195#24'+'
|
||||
+#169#19#167#160#27'c'#2#225#225#159#251#183'h'#174#173#167#169'='#144#169#150
|
||||
+'\'#226#19'_'#3' '#0'`'#213#162'hJN5)'#136'|'#149#146'_'#163#196#22' '#255
|
||||
+#151'H'#244'R6'#185#218'&'#174#212#212#211#211'i'#3'`T'#152#158'+'#183#251
|
||||
+#200#223#182#155#180#204'l*'#207#28#31#25#197#195#213'm'#194#146'g'#21#7#14
|
||||
+#28#20#235#215#173#22'B'#8'a'#201#179#14'{'#14#201#146'g'#21#178','#15#235#11
|
||||
+'!'#196#140#25'3'#132#16'B8'#31#221#21#0'*_'#131#229's'#199'J'#149';'#231'H'
|
||||
+#143';'#170#133#16'#'#250#255'}'#231#171#128''''#189#3#206'|>'#219'/'#182#148
|
||||
+#252#26#128'a'#24'}'#165'zR'#131#5#159#156#27#188'@$iX'#245#21#133'IT'#20'&)'
|
||||
+'FOm'#224#175'z_'#179'gF'#228#139#192#23#139'o'#219'l6c'#179#217'0'#155#205
|
||||
+#254'S4$'#223#20'='#173#134'R'#228#247#31#135#6#159'U'#225#250#241#18#255'{'
|
||||
+#253#11#27'BL'#144'\'#231'J]'#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
333
components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas
Normal file
333
components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas
Normal file
@ -0,0 +1,333 @@
|
||||
unit JDBTimeEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, LResources, Controls, StdCtrls, DB, DBCtrls, LMessages, LCLType, Dialogs,
|
||||
SysUtils, jcontrolutils;
|
||||
|
||||
type
|
||||
TJDBTimeEdit = class(TCustomEdit)
|
||||
private
|
||||
{ Private declarations }
|
||||
fFormat: string;
|
||||
FDataLink: TFieldDataLink;
|
||||
|
||||
procedure DataChange(Sender: TObject);
|
||||
procedure UpdateData(Sender: TObject);
|
||||
procedure FocusRequest(Sender: TObject);
|
||||
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
|
||||
function IsReadOnly: boolean;
|
||||
|
||||
function getFormat: string;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure formatInput;
|
||||
|
||||
procedure SetDataField(const Value: string);
|
||||
procedure SetDataSource(Value: TDataSource);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
|
||||
protected
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure ActiveChange(Sender: TObject); virtual;
|
||||
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||
procedure KeyPress(var Key: char); override;
|
||||
procedure DoEnter; override;
|
||||
function GetReadOnly: boolean; override;
|
||||
procedure SetReadOnly(Value: boolean); override;
|
||||
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure EditingDone; override;
|
||||
property Field: TField read GetField;
|
||||
|
||||
published
|
||||
property DisplayFormat: string read getFormat write setFormat;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property ReadOnly: boolean read GetReadOnly write SetReadOnly default False;
|
||||
|
||||
// From TEdit
|
||||
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 jdbtimeedit_icon.lrs}
|
||||
RegisterComponents('Data Controls', [TJDBTimeEdit]);
|
||||
end;
|
||||
|
||||
{ TJDBDateEdit }
|
||||
|
||||
procedure TJDBTimeEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
begin
|
||||
if not Focused then
|
||||
formatInput
|
||||
else
|
||||
Caption := FDataLink.Field.AsString;
|
||||
end
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.UpdateData(Sender: TObject);
|
||||
var
|
||||
theValue: string;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
begin
|
||||
theValue := NormalizeTime(Text, FDataLink.Field.AsDateTime);
|
||||
if Text = '' then
|
||||
begin
|
||||
Field.DataSet.Edit;
|
||||
Field.Value := Null;
|
||||
end
|
||||
else
|
||||
if IsValidTimeString(theValue) then
|
||||
begin
|
||||
FDataLink.Field.Text := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowMessage(Caption + ' no es una hora válida');
|
||||
Caption := FDataLink.Field.AsString;
|
||||
SelectAll;
|
||||
SetFocus;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.FocusRequest(Sender: TObject);
|
||||
begin
|
||||
SetFocus;
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.IsReadOnly: boolean;
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
Result := not FDatalink.CanModify
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
if not Focused then
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.formatInput;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
if (fFormat <> '') and (not FDataLink.Field.IsNull) then
|
||||
Caption := FormatDateTime(fFormat, FDataLink.Field.AsDateTime)
|
||||
else
|
||||
Caption := FDataLink.Field.DisplayText
|
||||
else
|
||||
Caption := 'nil';
|
||||
end;
|
||||
|
||||
function TJDBTimeEdit.GetReadOnly: boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.SetReadOnly(Value: boolean);
|
||||
begin
|
||||
inherited;
|
||||
FDataLink.ReadOnly := Value;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.SetDataField(const Value: string);
|
||||
begin
|
||||
FDataLink.FieldName := Value;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.SetDataSource(Value: TDataSource);
|
||||
begin
|
||||
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
|
||||
ChangeDataSource(Self, FDataLink, Value);
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility?
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.Notification(AComponent: TComponent; Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
// clean up
|
||||
if (Operation = opRemove) then
|
||||
begin
|
||||
if (FDataLink <> nil) and (AComponent = DataSource) then
|
||||
DataSource := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
datachange(Sender)
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.KeyDown(var Key: word; Shift: TShiftState);
|
||||
begin
|
||||
inherited KeyDown(Key, Shift);
|
||||
if Key = VK_ESCAPE then
|
||||
begin
|
||||
FDataLink.Reset;
|
||||
SelectAll;
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if Key in [VK_DELETE, VK_BACK] then
|
||||
begin
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit
|
||||
else
|
||||
Key := VK_UNKNOWN;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.KeyPress(var Key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, ':']) then
|
||||
Key := #0
|
||||
else
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.DoEnter;
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
Caption := FDataLink.Field.AsString;
|
||||
inherited DoEnter;
|
||||
end;
|
||||
|
||||
constructor TJDBTimeEdit.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
ControlStyle := ControlStyle + [csReplicatable];
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLInk.OnActiveChange := @ActiveChange;
|
||||
// Set default values
|
||||
//fFormat := ShortDateFormat;
|
||||
end;
|
||||
|
||||
destructor TJDBTimeEdit.Destroy;
|
||||
begin
|
||||
FDataLink.Free;
|
||||
FDataLink := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TJDBTimeEdit.EditingDone;
|
||||
begin
|
||||
inherited EditingDone;
|
||||
UpdateData(self);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
53
components/jujiboutils/jujibo-utils/src/jdbtimeedit_icon.lrs
Normal file
53
components/jujiboutils/jujibo-utils/src/jdbtimeedit_icon.lrs
Normal file
@ -0,0 +1,53 @@
|
||||
LazarusResources.Add('tjdbtimeedit','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#14
|
||||
+#4#1'm'#6#147#131#0#0#4'KIDATH'#199#181#150'mLSW'#24#199#127#183'/'#180#244
|
||||
+#189'E'#218#225'DT|A('#206'h'#135'/h'#230#192')q.'#147'mQ'#19#191','#190#236
|
||||
+#195#246'a/'#31'`'#153#31'7'#179#17#179'e'#203#150'}1'#146'hb6'#183'%'#142
|
||||
+#197#152'ME'#167#22'$'#216'M'#17'T'#156#10#2#130'Pk'#161#208#210#23#218'{'
|
||||
+#246#129#148#180#163'.'#234#178#127'rr'#238#185#185#247#249'?'#247'w'#158'{'
|
||||
+#206#145#132#16'<'#169'~?'#186#191'B'#163#12#238#213'hcK'#149'j'#165'1'#17#23
|
||||
+#132'Ca'#127'(HK8'#158']'#247#234'['#251'.&'#159#149'R'#13#190#191'p_'#28'8'
|
||||
+#222#149'1'#232#158#205#243#216#190'6O'#186#240#227#167#223'Z,'#163#187#172#5
|
||||
+'['#178'4'#166'\4:+B'#200#4'G'#6#240#223#187#206'@'#231#217'P`L]'#183#245#189
|
||||
+#175'?'#158'2H'#13#252#213';'#207#225#156'm'#160#163'7'#136'w$'#138'7'#16#195
|
||||
+';'#18#165#193#221#207#198'Y'#183'y}u'#24'['#193'&'#30#140#27'i'#191#19#192
|
||||
+';<N<!'#176#26#181#148#20#26#176#138'.n'#156'?'#204#144'7^'#243#230'G'#7#246
|
||||
+'KB'#8'*k'#155#196#146#5'6'#230':'#178'q'#22#24#177'[4i'#193#189#129#24'YQ/U'
|
||||
+#246'_(\'#241'6'#215#7'4'#248'F'#162','#153'o'#195'bR '#144#240#7#18#180'v>'
|
||||
+#192#160'Q'#176#216't'#19#207#241'C'#227'a'#165'm'#141#2'`^'#190#137#171#183
|
||||
+#252'4'#184#251#211#130'&'#251'P$'#193'3'#145'Vl'#249#21'<'#8#155#24#244'G'
|
||||
+#168'^7'#7#155'Q'#224#15#6'1'#152#244#204#206'7'#177'e}!Cc2>E1'#142#185#207
|
||||
+#234#18#227#195#31#168#146#140'W'#149#230'b7g'#241#168'9'#216#232#244#162#183
|
||||
+'m'#224'L'#167#159'e'#197'v'#198#227#2#181'Z'#205#169#223#142#241#198'k'#213
|
||||
+'dk'#181#156':'#215'L'#241#194'e\'#252#163#135#170#133'e'#220#189#241#195#26
|
||||
+#21'@W'#223'('#14'K.'#0'{w'#20'Q'#177'$g'#218#28'('#135'#h'#245'V'#6'|'#15'y'
|
||||
+')'''#155'hB'#160#215#233#184#215#219#203#169'3'#231'ho'#187'B'#229#198'*'
|
||||
+#172'v'#29#247#253#17#204'+'#231#160'Dr'#168#146#136'Z'#175#249'H'#200#2'gAQ'
|
||||
+#198'/'#136#133'c'#200'r'#148'pL&'#154#152#188#231#13#140#161'7'#24'ho'#187
|
||||
+#194#203'['#170'Y'#236','#165'''0'#193#196#132#140#144'c'#8'Y0'#133#168#172
|
||||
+'d'#6'vs'#22#251#142't'#178#239#200't'#131#221'3U'#4#134#254#194#172#159'I'
|
||||
+#247#224'8'#11'f'#153'A'#161'e'#153'k%E'#165'Ntf'#19#193'('#244#13#134'0'#233
|
||||
+#21#12#247#183#17#137'''|'#143#141#200#215'U@'#223#245's'#148#21#237#228#252
|
||||
+#229'!'#138#11#205'h'#149'j'#214#172']'#13#18'$dPj'#225#210'e//'#148'('#232
|
||||
+#249#179#153#9#161'j'#201#136#168#190#254'pZ'#246#6#0#173#142#158#155'='#172
|
||||
+'(l!'#223'XB'#253'O7'#217#240#188#131#249#14'='#8#232#245#134'8'#222'2'#200
|
||||
+#236'l'#31#185#225#179'4w'#133#145#178's&'#255#131'='#223#180#11#135'E'#131
|
||||
+#221#156'E'#131#187#159#29#139#238#208'q'#245#194'4L9Z'#153'y'#214'1'#150#174
|
||||
+'{'#145'!E'#25#23#175#197#25#25'K'#144#144#5'F'#29#172'*'#22#204#136#158#228
|
||||
+#210#201'V'#22#149'oe'#221'+;%'#21'@O'#255#24#14#139'f'#10#209']'#207#29#0
|
||||
+#190#248#242#192'4'#19#207#217#159'i9q'#148#156'<7U'#11'K'#176#228#21#128#136
|
||||
+#243#240#222'-'#238#182't'#208#237'SSZ'#177#11'g'#217'J'#128#201'I'#222#185
|
||||
+'i.'#245''''#186'3VQem'#19#141'u'#229'S'#227#218'_s'#177'J'#219#216'e'#236
|
||||
+#166#173#169#131#208#168#7#0#189#201'J'#219#237#8#181#159'|'#206#230#234'm'
|
||||
+#156'9}l'#242#5'!'#196'T'#251#238#252#128#168#168'q'#139#131#7#15#137#247#223
|
||||
+#221'-'#132#16#162#162#198#157#214'''UQ'#227#22#178','#167#141#133#16'b'#249
|
||||
+#242#229'B'#8'!'#2#195#189'B'#8#129'"5'#219#237'k'#243#164#198#186'r'#233#223
|
||||
+#150#234#127'.'#239#201#228#30'%'#213#227#238#1#167'?['#157#17'[em'#19'@'#26
|
||||
+#198'T)'#30#215'`'#253#135#205#147#27#136'$'#165'e'#223'XWNc]'#249#148#209'S'
|
||||
+#27'd'#202'>'#213#236'?#JE'#144#138'%'#245#218#229'r'#225#241'xp'#185'\'#153
|
||||
+#171'('#217'R'#171#232'i'#149#172'")S'#5#140#142#244'='#249'I '#131'L'#150'|'
|
||||
+'Iz'#154'S'#197#147'H'#193#255#172#191#1#24#252#148'+'#194#194#231'$'#0#0#0#0
|
||||
+'IEND'#174'B`'#130
|
||||
]);
|
Reference in New Issue
Block a user