From e2a77aa3a045ec4bec65c82603c256a6cb9091d8 Mon Sep 17 00:00:00 2001 From: jujibo Date: Mon, 19 Sep 2011 15:10:55 +0000 Subject: [PATCH] Added: Labeled db widgets git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1971 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jujiboutils/changes.txt | 1 + .../src/jdblabeledcurrencyedit.pas | 380 ++++++++++++++++++ .../jujibo-utils/src/jdblabeleddateedit.pas | 348 ++++++++++++++++ .../src/jdblabeledintegeredit.pas | 337 ++++++++++++++++ .../jujibo-utils/src/lcurrencydbicon.lrs | 34 ++ .../jujibo-utils/src/ldatedbicon.lrs | 31 ++ .../jujibo-utils/src/lintegerdbicon.lrs | 32 ++ 7 files changed, 1163 insertions(+) create mode 100644 components/jujiboutils/jujibo-utils/src/jdblabeledcurrencyedit.pas create mode 100644 components/jujiboutils/jujibo-utils/src/jdblabeleddateedit.pas create mode 100644 components/jujiboutils/jujibo-utils/src/jdblabeledintegeredit.pas create mode 100644 components/jujiboutils/jujibo-utils/src/lcurrencydbicon.lrs create mode 100644 components/jujiboutils/jujibo-utils/src/ldatedbicon.lrs create mode 100644 components/jujiboutils/jujibo-utils/src/lintegerdbicon.lrs diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index 3ad99aa8d..88e04bede 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -5,6 +5,7 @@ JUJIBOUTILS Version pre-1.0 -------------------------------------------------- +2011-09-19 Added: JDBLabeledIntegerEdit, TJDBLabeledCurrencyEdit, TJDBLabeledDateEdit 2011-09-19 First package: TJDBIntegerEdit, TJDBCurrencyEdit, TJDBDateEdit and example 2011-09-14 Add Non Database input controls example 2011-09-13 Initial commit to lazarus-ccr diff --git a/components/jujiboutils/jujibo-utils/src/jdblabeledcurrencyedit.pas b/components/jujiboutils/jujibo-utils/src/jdblabeledcurrencyedit.pas new file mode 100644 index 000000000..12d3334b9 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdblabeledcurrencyedit.pas @@ -0,0 +1,380 @@ +unit jdblabeledcurrencyedit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, LResources, Controls, StdCtrls, ExtCtrls, DB, DBCtrls, + LMessages, LCLType, Dialogs, + SysUtils; + +type + + { TJDBLabeledCurrencyEdit } + + TJDBLabeledCurrencyEdit = class(TLabeledEdit) + private + fFormat: string; + FDataLink: TFieldDataLink; + fDecimales: integer; + + procedure DataChange(Sender: TObject); + function getDecimals: integer; + procedure setDecimals(AValue: integer); + 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; + + function IsValidCurrency(const Value: string): boolean; + function ScaleTo(const AValue: currency; const NDecimals: integer): currency; + + 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 Decimals: integer read getDecimals write setDecimals; + 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 EchoMode; + 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 + +uses + Math; + +procedure Register; +begin + {$I lcurrencydbicon.lrs} + RegisterComponents('Data Controls', [TJDBLabeledCurrencyEdit]); +end; + +{ TJDBLabeledCurrencyEdit } + +procedure TJDBLabeledCurrencyEdit.DataChange(Sender: TObject); +begin + if FDataLink.Field <> nil then + begin + if not Focused then + formatInput + else + Caption := FDataLink.Field.AsString; + end + else + Text := ''; +end; + +function TJDBLabeledCurrencyEdit.getDecimals: integer; +begin + Result := fDecimales; +end; + +procedure TJDBLabeledCurrencyEdit.setDecimals(AValue: integer); +begin + if AValue >= 0 then + fDecimales := AValue; +end; + + +procedure TJDBLabeledCurrencyEdit.UpdateData(Sender: TObject); +var + theValue: currency; +begin + if FDataLink.Field <> nil then + begin + if IsValidCurrency(Text) then + begin + theValue := StrToCurr(Text); + theValue := ScaleTo(theValue, fDecimales); + Text := CurrToStr(theValue); + FDataLink.Field.Text := Text; + end + else + begin + if FDataLink.Field <> nil then + begin + ShowMessage(Caption + ' no es un valor válido'); + Caption := FDataLink.Field.AsString; + SelectAll; + SetFocus; + end; + end; + end + else + Text := ''; +end; + +procedure TJDBLabeledCurrencyEdit.FocusRequest(Sender: TObject); +begin + SetFocus; +end; + +function TJDBLabeledCurrencyEdit.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBLabeledCurrencyEdit.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBLabeledCurrencyEdit.GetField: TField; +begin + Result := FDataLink.Field; +end; + +function TJDBLabeledCurrencyEdit.IsReadOnly: boolean; +begin + if FDatalink.Active then + Result := not FDatalink.CanModify + else + Result := False; +end; + +function TJDBLabeledCurrencyEdit.getFormat: string; +begin + Result := fFormat; +end; + +procedure TJDBLabeledCurrencyEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + if not Focused then + formatInput; +end; + +procedure TJDBLabeledCurrencyEdit.formatInput; +begin + if FDataLink.Field <> nil then + //FDataLink.Field.DisplayText -> formatted (tdbgridcolumns/persistent field DisplayFormat + if fFormat <> '' then + Caption := FormatFloat(fFormat, FDataLink.Field.AsCurrency) + else + Caption := FDataLink.Field.DisplayText + else + Caption := 'nil'; +end; + +function TJDBLabeledCurrencyEdit.GetReadOnly: boolean; +begin + Result := FDataLink.ReadOnly; +end; + +procedure TJDBLabeledCurrencyEdit.SetReadOnly(Value: boolean); +begin + inherited; + FDataLink.ReadOnly := Value; +end; + +procedure TJDBLabeledCurrencyEdit.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBLabeledCurrencyEdit.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBLabeledCurrencyEdit.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility? +end; + +function TJDBLabeledCurrencyEdit.IsValidCurrency(const Value: string): boolean; +begin + if StrToCurrDef(Value, MaxCurrency) = MaxCurrency then + Result := False + else + Result := True; +end; + +function TJDBLabeledCurrencyEdit.ScaleTo(const AValue: currency; + const NDecimals: integer): currency; +begin + Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals); +end; + +procedure TJDBLabeledCurrencyEdit.Loaded; +begin + inherited Loaded; + if (csDesigning in ComponentState) then + DataChange(Self); +end; + +procedure TJDBLabeledCurrencyEdit.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 TJDBLabeledCurrencyEdit.ActiveChange(Sender: TObject); +begin + if FDatalink.Active then + datachange(Sender) + else + Text := ''; +end; + +procedure TJDBLabeledCurrencyEdit.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 TJDBLabeledCurrencyEdit.KeyPress(var Key: char); +begin + if (Key in ['.', ',']) then + Key := Decimalseparator; + if (key = DecimalSeparator) and (Pos(key, Text) > 0) then + key := #0; + if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then + Key := #0; + if (Key = DecimalSeparator) and (fDecimales = 0) then + Key := #0; + + if (Key <> #0) and (not IsReadOnly) then + FDatalink.Edit; + inherited KeyPress(Key); +end; + +procedure TJDBLabeledCurrencyEdit.DoEnter; +begin + if FDataLink.Field <> nil then + Caption := FDataLink.Field.AsString; + inherited DoEnter; +end; + +constructor TJDBLabeledCurrencyEdit.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 + //fDecimales := 2; + //fFormat := '0.00'; +end; + +destructor TJDBLabeledCurrencyEdit.Destroy; +begin + FDataLink.Free; + FDataLink := nil; + inherited Destroy; +end; + +procedure TJDBLabeledCurrencyEdit.EditingDone; +begin + inherited EditingDone; + UpdateData(self); +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jdblabeleddateedit.pas b/components/jujiboutils/jujibo-utils/src/jdblabeleddateedit.pas new file mode 100644 index 000000000..11f689327 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdblabeleddateedit.pas @@ -0,0 +1,348 @@ +unit jdblabeleddateedit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, LResources, Controls, StdCtrls, ExtCtrls, DB, DBCtrls, LMessages, LCLType, Dialogs, + SysUtils; + +type + + { TJDBLabeledDateEdit } + + TJDBLabeledDateEdit = class(TLabeledEdit) + private + 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; + + function IsValidCurrency(const Value: string): boolean; + + 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 EchoMode; + 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 + +uses + jcontrolutils; + +procedure Register; +begin + {$I ldatedbicon.lrs} + RegisterComponents('Data Controls', [TJDBLabeledDateEdit]); +end; + +{ TJDBLabeledDateEdit } + +procedure TJDBLabeledDateEdit.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 TJDBLabeledDateEdit.UpdateData(Sender: TObject); +var + theValue: string; +begin + if FDataLink.Field <> nil then + begin + theValue := NormalizeDate(Text, FDataLink.Field.AsDateTime); + if Text = '' then + FDataLink.Field.Text := Text + else + if IsValidDateString(theValue) then + begin + FDataLink.Field.Text := theValue; + end + else + begin + ShowMessage(Caption + ' no es un valor válido'); + Caption := FDataLink.Field.AsString; + SelectAll; + SetFocus; + end; + end + else + Text := ''; +end; + +procedure TJDBLabeledDateEdit.FocusRequest(Sender: TObject); +begin + SetFocus; +end; + +function TJDBLabeledDateEdit.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBLabeledDateEdit.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBLabeledDateEdit.GetField: TField; +begin + Result := FDataLink.Field; +end; + +function TJDBLabeledDateEdit.IsReadOnly: boolean; +begin + if FDatalink.Active then + Result := not FDatalink.CanModify + else + Result := False; +end; + +function TJDBLabeledDateEdit.getFormat: string; +begin + Result := fFormat; +end; + +procedure TJDBLabeledDateEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + if not Focused then + formatInput; +end; + +procedure TJDBLabeledDateEdit.formatInput; +begin + if FDataLink.Field <> nil then + //FDataLink.Field.DisplayText -> formatted (tdbgridcolumns/persistent field DisplayFormat + if (fFormat <> '') and (not FDataLink.Field.IsNull) then + Caption := FormatDateTime(fFormat, FDataLink.Field.AsDateTime) + else + Caption := FDataLink.Field.DisplayText + else + Caption := 'nil'; +end; + +function TJDBLabeledDateEdit.GetReadOnly: boolean; +begin + Result := FDataLink.ReadOnly; +end; + +procedure TJDBLabeledDateEdit.SetReadOnly(Value: boolean); +begin + inherited; + FDataLink.ReadOnly := Value; +end; + +procedure TJDBLabeledDateEdit.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBLabeledDateEdit.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBLabeledDateEdit.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility? +end; + +function TJDBLabeledDateEdit.IsValidCurrency(const Value: string): boolean; +begin + if StrToCurrDef(Value, MaxCurrency) = MaxCurrency then + Result := False + else + Result := True; +end; + +procedure TJDBLabeledDateEdit.Loaded; +begin + inherited Loaded; + if (csDesigning in ComponentState) then + DataChange(Self); +end; + +procedure TJDBLabeledDateEdit.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 TJDBLabeledDateEdit.ActiveChange(Sender: TObject); +begin + if FDatalink.Active then + datachange(Sender) + else + Text := ''; +end; + +procedure TJDBLabeledDateEdit.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 TJDBLabeledDateEdit.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 TJDBLabeledDateEdit.DoEnter; +begin + if FDataLink.Field <> nil then + Caption := FDataLink.Field.AsString; + inherited DoEnter; +end; + +constructor TJDBLabeledDateEdit.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 TJDBLabeledDateEdit.Destroy; +begin + FDataLink.Free; + FDataLink := nil; + inherited Destroy; +end; + +procedure TJDBLabeledDateEdit.EditingDone; +begin + inherited EditingDone; + UpdateData(self); +end; + +end. + + + diff --git a/components/jujiboutils/jujibo-utils/src/jdblabeledintegeredit.pas b/components/jujiboutils/jujibo-utils/src/jdblabeledintegeredit.pas new file mode 100644 index 000000000..119b459e7 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdblabeledintegeredit.pas @@ -0,0 +1,337 @@ +unit jdblabeledintegeredit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, LResources, Controls, StdCtrls, ExtCtrls, DB, DBCtrls, + LMessages, LCLType, Dialogs, + SysUtils; + +type + + { TJDBLabeledIntegerEdit } + + TJDBLabeledIntegerEdit = class(TLabeledEdit) + private + 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; + + function IsValidInteger(const Value: string): boolean; + + 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 EchoMode; + 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 lintegerdbicon.lrs} + RegisterComponents('Data Controls', [TJDBLabeledIntegerEdit]); +end; + +{ TJDBLabeledIntegerEdit } + +procedure TJDBLabeledIntegerEdit.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 TJDBLabeledIntegerEdit.UpdateData(Sender: TObject); +begin + if FDataLink.Field <> nil then + begin + if IsValidInteger(Caption) then + FDataLink.Field.Text := Text + else + begin + ShowMessage(Caption + ' no es un valor válido'); + Caption := FDataLink.Field.AsString; + SelectAll; + SetFocus; + end; + end + else + Text := ''; +end; + +procedure TJDBLabeledIntegerEdit.FocusRequest(Sender: TObject); +begin + SetFocus; +end; + +function TJDBLabeledIntegerEdit.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBLabeledIntegerEdit.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBLabeledIntegerEdit.GetField: TField; +begin + Result := FDataLink.Field; +end; + +function TJDBLabeledIntegerEdit.IsReadOnly: boolean; +begin + if FDatalink.Active then + Result := not FDatalink.CanModify + else + Result := False; +end; + +function TJDBLabeledIntegerEdit.getFormat: string; +begin + Result := fFormat; +end; + +procedure TJDBLabeledIntegerEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + if not Focused then + formatInput; +end; + +procedure TJDBLabeledIntegerEdit.formatInput; +begin + if FDataLink.Field <> nil then + //FDataLink.Field.DisplayText -> formatted (tdbgridcolumns/persistent field DisplayFormat + if fFormat <> '' then + Caption := FormatFloat(fFormat, FDataLink.Field.AsInteger) + else + Caption := FDataLink.Field.DisplayText + else + Caption := 'nil'; +end; + +function TJDBLabeledIntegerEdit.GetReadOnly: boolean; +begin + Result := FDataLink.ReadOnly; +end; + +procedure TJDBLabeledIntegerEdit.SetReadOnly(Value: boolean); +begin + inherited; + FDataLink.ReadOnly := Value; +end; + +procedure TJDBLabeledIntegerEdit.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBLabeledIntegerEdit.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBLabeledIntegerEdit.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility? +end; + +function TJDBLabeledIntegerEdit.IsValidInteger(const Value: string): boolean; +begin + if StrToIntDef(Value, MaxInt) = MaxInt then + Result := False + else + Result := True; +end; + +procedure TJDBLabeledIntegerEdit.Loaded; +begin + inherited Loaded; + if (csDesigning in ComponentState) then + DataChange(Self); +end; + +procedure TJDBLabeledIntegerEdit.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 TJDBLabeledIntegerEdit.ActiveChange(Sender: TObject); +begin + if FDatalink.Active then + datachange(Sender) + else + Text := ''; +end; + +procedure TJDBLabeledIntegerEdit.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 TJDBLabeledIntegerEdit.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 TJDBLabeledIntegerEdit.DoEnter; +begin + if FDataLink.Field <> nil then + Caption := FDataLink.Field.AsString; + inherited DoEnter; +end; + +constructor TJDBLabeledIntegerEdit.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; +end; + +destructor TJDBLabeledIntegerEdit.Destroy; +begin + FDataLink.Free; + FDataLink := nil; + inherited Destroy; +end; + +procedure TJDBLabeledIntegerEdit.EditingDone; +begin + inherited EditingDone; + UpdateData(self); +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/lcurrencydbicon.lrs b/components/jujiboutils/jujibo-utils/src/lcurrencydbicon.lrs new file mode 100644 index 000000000..dab587a17 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/lcurrencydbicon.lrs @@ -0,0 +1,34 @@ +LazarusResources.Add('TJDBLabeledCurrencyEdit','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#19#14 + +'4$v&'#230'`'#0#0#2'zIDATH'#199#213#149'=hSQ'#20#199#255'7'#196#138#16'Z'#218 + +'M'#165#25#2'E'#7'm)7'#224#144#226#16#151#14#138#131'Y'#172#131'J#'#194#205 + +#16#187#164#131' '#197'%DD[j'#162#16#130#22'A'#151#183#20'*'#184'<'#7#137#184 + +#228'!'#164#130#31#129#162#149':' + +#26'j'#196#193#3#151#156's'#184#249#253#207'9'#239#228#5#248#199#198#212#224 + +#225#211#143'T\Y'#243#189'x'#225'x'#4#167#143#238'c='#9#168#224#133#212#24#14 + +#133'Cx'#185#254#21'f'#163#9#211'j'#193'l4'#177'\'#222#232'I('#0#0#197#149'5' + +#140#142#12#225#228#196'~'#152#141#166#3'~}'#230#4'L'#171#133#209#145'!D'#134 + +#251#177']'#135#170'q'#206#201'!'#16#25#238'G'#181'V'#199'ry'#195#174'X'#194 + +#1#224#241#252#20#170#181':&'#247#190#133#165#167#193'9''M'#211#200#13#227 + +#156#147#140#213'<'#146#139'U'#18'B'#216''''#158')'#19'@'#20#207#148#137'sN' + +#241'L'#153'.'#223#127'C'#156'sJ.V'#29#0'M'#211'H'#130#253'D'#131#0#208#247 + +#234#14#242#249#130'-'#152'J'#1#11#239#199'`6'#14'"'#163#163'3:'#171#5#0'xq' + +#239#188#3#144'H$'#152#140#19#137#132#231#217#4#132#16#164#194#1' '#159'/' + +#224'vn'#214#145'{'#190#250#9#0'0~'#238'.'#12#195'`'#134'a0'#217#129#188#163 + +#250#246#22#9'!HB'#183':'#16#0#128#215#161')Xz'#26#0'0y'#233#1#198#247#172'"' + +#155#205#218#247#12#195'`'#156's'#146'b'#210#151#29#25#134#193#152#236'@B' + +#165'X*%p'#234#226'U'#199'C'#255#246'}'#19#213'Z'#29'O'#174'M'#236'xM'#131'*' + +#212'm'#239'*'#143#0#0#161#223#7#1#224#240#1#224'Li'#137'v'#2#159#158'>'#203 + +#186#142'h'#247#174'V'#207#175#136#185#185'+'#24#24#12#179#160':'#18#247#136 + +'n'#204#23'{'#22#248#210#248#208'q'#132#16'D'#4#207#233#228';'#191#5#213#226 + +#153#178#157#251#241's'#211#17's'#206#237'O'#235#243':'#217#2'n'#145#173#156 + +'W@'#21'j'#183#219#142'X'#21#145#2']G'#228'gD'#4#198#152'#'#238'y'#139#182#3 + +#31#155'}'#6'='#23#179'}'#0'v'#236#251'6uW'#235'W'#189#132#187#171#215's1' + +#232#185#152'-'#228#233#160'P(0!'#4#185#161'7o'#229'}'#191#160'V'#175#138'u' + +#253'?'#224#252#136#7#222#199#188'`'#213#151#177#244#245'\'#12#209'h'#20#149 + +'J'#5#209'h'#180#187'j'#169#180'D3'#233#164'gk'#254#196#228#22#249#246'h'#239 + +#240'_'#218#192'`'#152#225#191#183'_'#230#221#8#6'h'#246#197#218#0#0#0#0'IEN' + +'D'#174'B`'#130 +]); diff --git a/components/jujiboutils/jujibo-utils/src/ldatedbicon.lrs b/components/jujiboutils/jujibo-utils/src/ldatedbicon.lrs new file mode 100644 index 000000000..86856617c --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/ldatedbicon.lrs @@ -0,0 +1,31 @@ +LazarusResources.Add('TJDBLabeledDateEdit','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#19#14 + +#16''''#30#199'V|'#0#0#2'j7'#254#31 + +#180#211'`c'#187'7'#232#244#186#180#239#26#248#161'P'#222#3#16#241#141'['#150 + +#5')%,'#203':'#153#192'Yc'#231'n*'#166'c.{'#168#235'zP'#231#179'$'#238'#'#240 + +':'#193#231#246#224#172#174#190#210#182#190'UG'#243#180#145#236#147#181#181 + +'<'#23#230#158#147'$'#167#23#171#252#245#251#15#167#23#171#182'('#191'j'#147 + +'TW'#131#173';?'#246'Ir0'#193#176'P'#4#154#215#163#127#212'n'#156'K'#185#130 + +#151#195#154'6'#234#191#138#0'F'#140#191'H'#218#196#13'W'#138'!N'#0#0#0#0'IE' + +'ND'#174'B`'#130 +]); diff --git a/components/jujiboutils/jujibo-utils/src/lintegerdbicon.lrs b/components/jujiboutils/jujibo-utils/src/lintegerdbicon.lrs new file mode 100644 index 000000000..7c122375d --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/lintegerdbicon.lrs @@ -0,0 +1,32 @@ +LazarusResources.Add('TJDBLabeledIntegerEdit','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#19#14 + +#13'*'#159#26'F'#221#0#0#2'jIDATH'#199#213#147'=H[Q'#28#197#127'W'#130'.'#173 + +'Q'#139#10#22'-'#13'H'#29#172#165#188'P(M'#29#146'A('#133'.YDJ'#253'*'#148'v' + +#144'.'#145' '#20';'#133'v('#13'.'#133' '#181'vp'#201'"'#216'1'#29'4.%'#15'!' + +#216'.'#162#248'A'#164#132'b'#19'?'#192'H'#146#235'P'#238#235'{'#249#16#155 + +#180'C'#207'r'#255#255#251#30#231#220#255#185#231#194'?'#134'07s'#139#187'2' + +#180#176'Q'#242#199#199#247#29#244#247#182#137#138#4#204#196#193'g7'#232#238 + +#184#192#234#246'!'#201'T'#134'd'#250#132'd*'#195'|4Q'#145'P'#13'@ha'#131#158 + +#206'&'#30#184'.'#147'Le'#12'r'#223'p'#159'!'#210#211#217#132#163#189#158'r' + +#19'*h'#154'&'#139#4#28#237#245#196#215#246#152#143'&'#140#19#251#134#251#0 + +#152'}'#233#229#232'8'#135#171#241#27'+3C'#164'#c'#132#195'aYH'#166'i'#154'T' + +#189'y_'#0#140'N'#197'ekC'#29'-'#246'Z'#195#10#128'td'#12#187'''h'#212'w'#159 + +'|'#228#240'8'#203#202#204#16#186#174#139'p8,'#3#129#0#0'~'#191#31#175#215'+' + +'4M'#147#186#174#27#22#218#0'6v'#246'imh'#6'`b'#160#11'w'#207'%V'#183#15#25 + +#140#252#242'<'#153#202'0'#27#129#165'w'#15'-v(BU'#151#189#3'G{=_'#190#254 + +#176#156#190#20#236#158' 7'#7#223#163'N'#168#172'*'#172#139'Rt'#150'E'#138 + +#248#233#173#239'(;'#0't]'#183#216#161'j5'#145#218#23#0'n_T'#222#190#222'L' + +#139#189#150#238'+'#23#13#139#204'1M'#166'O8:'#206#17'_'#219#227#243'k'#151 + +#248#163'w0:'#21#151'['#137#3'ry'#201#196'@'#23#155#177'O'#127#229#21#143#140 + +'<'#18'%-'#26#184#182#206'j|'#169'*'#242#201#201#23#216#27';'#132#13'`+q@kC' + +#157#145#162#205#216':'#0'o'#222#134'*'#22#216'O'#237#252'N'#209#240#189#171 + +'eS'#228#25'_6VUgsyK'#15#224't:-kI'#204'-'#238'J'#183'/*'#167#167'?'#200#231 + +'c'#163'RJ)'#221#190#168'4'#195#237#139#202'|>o'#233#21'4M3'#234#244#207'miL' + +#160#208#223#219'&'#202'%DJY'#212#23#238#149#130#237'<~*"'#207#248'2'#145'Ww' + +','#214#169#190'*'#1'!D'#145#160'Y'#232','#145#154#243#166#194'LT(X'#245#4 + +#217'\'#190#200#150'B'#139#156'N'''#177'X'#204'X'#207#132'9E'#149'B'#165#168 + +#228#172#234'c'#181#176'7v'#8#254'{'#156#2#250'='#180'%'#189#4'\'#190#0#0#0#0 + +'IEND'#174'B`'#130 +]);