You've already forked lazarus-ccr
Added: FloatEdit, TJLabeledFloatEdit. Examplenodb updated
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2022 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -6,6 +6,8 @@ Note: Lazarus Trunk required
|
||||
Version pre-1.0
|
||||
--------------------------------------------------
|
||||
2011-09-27 Added: ftDateTime support to TJDBGridControl
|
||||
TJFloatEdit, TJLabeledFloatEdit
|
||||
Examplenodb updated
|
||||
2011-09-26 Added: TJDateTimeEdit, TJLabeledDateTimeEdit
|
||||
TJDBDateTimeEdit, TJDBLabeledDateTimeEdit
|
||||
2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit,
|
||||
|
@ -1,11 +1,11 @@
|
||||
object Form1: TForm1
|
||||
Left = 378
|
||||
Left = 365
|
||||
Height = 295
|
||||
Top = 196
|
||||
Width = 332
|
||||
Top = 260
|
||||
Width = 419
|
||||
Caption = 'Example'
|
||||
ClientHeight = 295
|
||||
ClientWidth = 332
|
||||
ClientWidth = 419
|
||||
LCLVersion = '0.9.31'
|
||||
object Label1: TLabel
|
||||
Left = 8
|
||||
@ -22,10 +22,10 @@ object Form1: TForm1
|
||||
Left = 24
|
||||
Height = 82
|
||||
Top = 40
|
||||
Width = 288
|
||||
Width = 375
|
||||
Caption = 'Labeled controls'
|
||||
ClientHeight = 63
|
||||
ClientWidth = 284
|
||||
ClientWidth = 371
|
||||
TabOrder = 0
|
||||
object JLabeledIntegerEdit1: TJLabeledIntegerEdit
|
||||
Left = 14
|
||||
@ -35,11 +35,13 @@ object Form1: TForm1
|
||||
DisplayFormat = '0'
|
||||
Value = 0
|
||||
EditLabel.AnchorSideLeft.Control = JLabeledIntegerEdit1
|
||||
EditLabel.AnchorSideRight.Control = JLabeledIntegerEdit1
|
||||
EditLabel.AnchorSideRight.Side = asrBottom
|
||||
EditLabel.AnchorSideBottom.Control = JLabeledIntegerEdit1
|
||||
EditLabel.Left = 14
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 2
|
||||
EditLabel.Width = 45
|
||||
EditLabel.Width = 80
|
||||
EditLabel.Caption = 'Integer'
|
||||
EditLabel.ParentColor = False
|
||||
TabOrder = 0
|
||||
@ -53,11 +55,13 @@ object Form1: TForm1
|
||||
Decimals = 2
|
||||
Value = 0
|
||||
EditLabel.AnchorSideLeft.Control = JLabeledCurrencyEdit1
|
||||
EditLabel.AnchorSideRight.Control = JLabeledCurrencyEdit1
|
||||
EditLabel.AnchorSideRight.Side = asrBottom
|
||||
EditLabel.AnchorSideBottom.Control = JLabeledCurrencyEdit1
|
||||
EditLabel.Left = 102
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 2
|
||||
EditLabel.Width = 55
|
||||
EditLabel.Width = 80
|
||||
EditLabel.Caption = 'Currency'
|
||||
EditLabel.ParentColor = False
|
||||
TabOrder = 1
|
||||
@ -70,24 +74,46 @@ object Form1: TForm1
|
||||
DisplayFormat = 'dd/mm/yy'
|
||||
Value = 0
|
||||
EditLabel.AnchorSideLeft.Control = JLabeledDateEdit1
|
||||
EditLabel.AnchorSideRight.Control = JLabeledDateEdit1
|
||||
EditLabel.AnchorSideRight.Side = asrBottom
|
||||
EditLabel.AnchorSideBottom.Control = JLabeledDateEdit1
|
||||
EditLabel.Left = 190
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 1
|
||||
EditLabel.Width = 29
|
||||
EditLabel.Width = 80
|
||||
EditLabel.Caption = 'Date'
|
||||
EditLabel.ParentColor = False
|
||||
TabOrder = 2
|
||||
end
|
||||
object JLabeledFloatEdit1: TJLabeledFloatEdit
|
||||
Left = 280
|
||||
Height = 27
|
||||
Top = 23
|
||||
Width = 80
|
||||
DisplayFormat = '#,0.00'
|
||||
Decimals = 2
|
||||
Value = 0
|
||||
EditLabel.AnchorSideLeft.Control = JLabeledFloatEdit1
|
||||
EditLabel.AnchorSideRight.Control = JLabeledFloatEdit1
|
||||
EditLabel.AnchorSideRight.Side = asrBottom
|
||||
EditLabel.AnchorSideBottom.Control = JLabeledFloatEdit1
|
||||
EditLabel.Left = 280
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 2
|
||||
EditLabel.Width = 80
|
||||
EditLabel.Caption = 'Float'
|
||||
EditLabel.ParentColor = False
|
||||
TabOrder = 3
|
||||
end
|
||||
end
|
||||
object GroupBox2: TGroupBox
|
||||
Left = 24
|
||||
Height = 105
|
||||
Top = 128
|
||||
Width = 288
|
||||
Width = 376
|
||||
Caption = 'Normal Controls'
|
||||
ClientHeight = 86
|
||||
ClientWidth = 284
|
||||
ClientWidth = 372
|
||||
TabOrder = 1
|
||||
object JIntegerEdit1: TJIntegerEdit
|
||||
Left = 14
|
||||
@ -117,9 +143,19 @@ object Form1: TForm1
|
||||
Value = 0
|
||||
TabOrder = 2
|
||||
end
|
||||
object JFloatEdit1: TJFloatEdit
|
||||
Left = 280
|
||||
Height = 27
|
||||
Top = 24
|
||||
Width = 80
|
||||
DisplayFormat = '#,0.00'
|
||||
Decimals = 2
|
||||
Value = 0
|
||||
TabOrder = 3
|
||||
end
|
||||
end
|
||||
object BitBtn1: TBitBtn
|
||||
Left = 221
|
||||
Left = 308
|
||||
Height = 30
|
||||
Top = 249
|
||||
Width = 91
|
||||
|
@ -7,7 +7,8 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
Buttons, JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit,
|
||||
JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit;
|
||||
JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit, JFloatEdit,
|
||||
JLabeledFloatEdit;
|
||||
|
||||
type
|
||||
|
||||
@ -19,9 +20,11 @@ type
|
||||
GroupBox2: TGroupBox;
|
||||
JCurrencyEdit1: TJCurrencyEdit;
|
||||
JDateEdit1: TJDateEdit;
|
||||
JFloatEdit1: TJFloatEdit;
|
||||
JIntegerEdit1: TJIntegerEdit;
|
||||
JLabeledCurrencyEdit1: TJLabeledCurrencyEdit;
|
||||
JLabeledDateEdit1: TJLabeledDateEdit;
|
||||
JLabeledFloatEdit1: TJLabeledFloatEdit;
|
||||
JLabeledIntegerEdit1: TJLabeledIntegerEdit;
|
||||
JLabeledIntegerEdit2: TJLabeledIntegerEdit;
|
||||
Label1: TLabel;
|
||||
|
@ -6,7 +6,6 @@
|
||||
<MainUnit Value="0"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
@ -61,6 +60,10 @@
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="True"/>
|
||||
<DebugInfoType Value="dsAuto"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Files Count="24">
|
||||
<Files Count="26">
|
||||
<Item1>
|
||||
<Filename Value="src/jdbintegeredit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -137,6 +137,16 @@
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JDBLabeledDateTimeEdit"/>
|
||||
</Item24>
|
||||
<Item25>
|
||||
<Filename Value="src/jfloatedit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JFloatEdit"/>
|
||||
</Item25>
|
||||
<Item26>
|
||||
<Filename Value="src/jlabeledfloatedit.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="JLabeledFloatEdit"/>
|
||||
</Item26>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="2">
|
||||
|
@ -12,8 +12,8 @@ uses
|
||||
JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit,
|
||||
JDateEdit, JLabeledDateEdit, JDBGridControl, jdbgridutils, JDBLabeledEdit,
|
||||
JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit, JDateTimeEdit,
|
||||
JLabeledDateTimeEdit, JDBDateTimeEdit, JDBLabeledDateTimeEdit,
|
||||
LazarusPackageIntf;
|
||||
JLabeledDateTimeEdit, JDBDateTimeEdit, JDBLabeledDateTimeEdit, JFloatEdit,
|
||||
JLabeledFloatEdit, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
@ -41,6 +41,8 @@ begin
|
||||
RegisterUnit('JLabeledDateTimeEdit', @JLabeledDateTimeEdit.Register);
|
||||
RegisterUnit('JDBDateTimeEdit', @JDBDateTimeEdit.Register);
|
||||
RegisterUnit('JDBLabeledDateTimeEdit', @JDBLabeledDateTimeEdit.Register);
|
||||
RegisterUnit('JFloatEdit', @JFloatEdit.Register);
|
||||
RegisterUnit('JLabeledFloatEdit', @JLabeledFloatEdit.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
227
components/jujiboutils/jujibo-utils/src/jfloatedit.pas
Normal file
227
components/jujiboutils/jujibo-utils/src/jfloatedit.pas
Normal file
@ -0,0 +1,227 @@
|
||||
{ JFloatEdit
|
||||
|
||||
Copyright (C) 2011 Julio Jiménez Borreguero
|
||||
Contact: jujibo at gmail dot com
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the same terms as the Lazarus Component Library (LCL)
|
||||
|
||||
See the file license-jujiboutils.txt and COPYING.LGPL, included in this distribution,
|
||||
for details about the license.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
}
|
||||
|
||||
unit JFloatEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Graphics, Dialogs;
|
||||
|
||||
type
|
||||
|
||||
{ TJFloatEdit }
|
||||
|
||||
TJFloatEdit = class(TCustomEdit)
|
||||
private
|
||||
{ Private declarations }
|
||||
theValue: double;
|
||||
fFormat: string;
|
||||
fDecimals: integer;
|
||||
function getDecimals: integer;
|
||||
function getFormat: string;
|
||||
function getValue: double;
|
||||
procedure formatInput;
|
||||
procedure setDecimals(const AValue: integer);
|
||||
procedure setFormat(const AValue: string);
|
||||
function scaleTo(const AValue: double; const NDecimals: integer): double;
|
||||
function IsValidFloat(const Value: string): boolean;
|
||||
procedure setValue(const AValue: double);
|
||||
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 }
|
||||
property DisplayFormat: string read getFormat write setFormat;
|
||||
property Decimals: integer read getDecimals write setDecimals;
|
||||
property Value: double 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
|
||||
|
||||
uses
|
||||
Math;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
{$I jfloatedit_icon.lrs}
|
||||
RegisterComponents('Additional', [TJFloatEdit]);
|
||||
end;
|
||||
|
||||
|
||||
function TJFloatEdit.getDecimals: integer;
|
||||
begin
|
||||
Result := fDecimals;
|
||||
end;
|
||||
|
||||
function TJFloatEdit.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
function TJFloatEdit.getValue: double;
|
||||
begin
|
||||
Result := theValue;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.formatInput;
|
||||
begin
|
||||
Caption := FormatFloat(DisplayFormat, theValue);
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.setDecimals(const AValue: integer);
|
||||
begin
|
||||
if (AValue >= 0) and (AValue < 12) then
|
||||
fDecimals := AValue;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
function TJFloatEdit.scaleTo(const AValue: double; const NDecimals: integer): double;
|
||||
begin
|
||||
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
||||
end;
|
||||
|
||||
function TJFloatEdit.IsValidFloat(const Value: string): boolean;
|
||||
begin
|
||||
if StrToFloatDef(Value, MaxDouble) = MaxDouble then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.setValue(const AValue: double);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.DoEnter;
|
||||
begin
|
||||
inherited DoEnter;
|
||||
Text := FloatToStr(theValue);
|
||||
SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.DoExit;
|
||||
begin
|
||||
inherited DoExit;
|
||||
if IsValidFloat(Text) then
|
||||
theValue := StrToCurr(Text)
|
||||
else
|
||||
begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJFloatEdit.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 (fDecimals = 0) then
|
||||
Key := #0;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
constructor TJFloatEdit.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
Text := '';
|
||||
fFormat := '#,0.00';
|
||||
fDecimals := 2;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
destructor TJFloatEdit.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
28
components/jujiboutils/jujibo-utils/src/jfloatedit_icon.lrs
Normal file
28
components/jujiboutils/jujibo-utils/src/jfloatedit_icon.lrs
Normal file
@ -0,0 +1,28 @@
|
||||
LazarusResources.Add('tjfloatedit','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#27#9
|
||||
+'.'#16'''D'#214'd'#0#0#2#10'IDATH'#199#213#150#177'K[Q'#20#198#127'7'#20#165
|
||||
+#208#198#208'6'#9#14#169#24'('#13'4'#218'!'#143#130#4#151#184#149#254#1'B'
|
||||
+#160'C'#168'S'#135#210'%'#14'Bqq'#200'RZ'#232'&'#14#14#162'k'#161#29#179#212
|
||||
+'HA2E'#133'BhPCZH'#197'&'#209#130#6#243'N'#135#246#166'/'#230#5#243#162#25
|
||||
+#250#193#229#190#243#184'|'#223#185#223'9'#239#240#148#136#208'O\'#179#6'k'
|
||||
+#235#223'Y'#252'P'#176'=8'#243'$'#200#244#228#176'c'#1'%"-'#196'o'#159'?$|'
|
||||
+#247#6#219#251#199#148'+'#167#148#171'u'#202#149'S'#222'gJ='#9')'#17'ajv'#131
|
||||
+#241'{'#183#24#245'_''<r'#19#159'g'#176#133#188'\'#173#243#235#164#193#241
|
||||
+#201#25#133'b'#141't*'#234#204#162'`'#192'M.'#127'H.'#15'>O'#16#160#141'<'
|
||||
+#151'?D'#159#237#169#6#19'c^|C'#3#29'k01'#230'm'#222#194#177'@'#161'X'#195
|
||||
+#239#241#2'0'#23#15#17#27#191#221'V'#131'r'#181#142'>'#235'X '#24'p'#179#185
|
||||
+'s@'#195#20#194'#!'#219#131#159#183'~\'#206#162'G'#15#238#224#27#26'`a'#229
|
||||
+#11#11'+'#255#145'EJD'#152'y'#183#197'^'#233#136#134')'#204#197'C'#236'f?^'
|
||||
+#201#231#157'H<U'#182#22#197#239#195'vn'#253'R'#228#243#243#175#254'Y'#180'W'
|
||||
+':'#194#239#25'lZ'#180#155#253#10#192#235'7'#139'='#11#212'*E'#0'\'#0#137#199
|
||||
+#163'l'#238#28'4'#199#129#21'S'#179#27'm'#177'~w'#214'0[b'#195'0Zv'#0'D'#164
|
||||
+#185'V?}#'#150#204#176#180#180',/_<'#19#17#145'X2#v'#136'%3b'#154'fK,"'#18
|
||||
+#137'DDD'#164#250's_D'#228#207#13'4'#166''''#135'/'#156'3'#231#199#187'N'#174
|
||||
+#171'q}'#17#177'R'#170'i'#147'ND'#219#211')1W'#215#253#252#151'\'#239'Z4'#157
|
||||
+#138#146'NE'#219'j'#229'X'#192'Zd'#157#173'U'#172#19'\N'#136#237':I?'#167'SQ'
|
||||
+#12#195' '#155#205'v'#238'"'#189#172']t'#190'K'#186#133#238'"e'#215#1#181'J'
|
||||
+#241'JF'#133#219#19'P'#170#223#127#21'.'#250#140#223' -'#161#12#164#195#188
|
||||
+#207#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
223
components/jujiboutils/jujibo-utils/src/jlabeledfloatedit.pas
Normal file
223
components/jujiboutils/jujibo-utils/src/jlabeledfloatedit.pas
Normal file
@ -0,0 +1,223 @@
|
||||
{ JLabeledFloatEdit
|
||||
|
||||
Copyright (C) 2011 Julio Jiménez Borreguero
|
||||
Contact: jujibo at gmail dot com
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the same terms as the Lazarus Component Library (LCL)
|
||||
|
||||
See the file license-jujiboutils.txt and COPYING.LGPL, included in this distribution,
|
||||
for details about the license.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
}
|
||||
|
||||
unit JLabeledFloatEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, ExtCtrls, Graphics, Dialogs;
|
||||
|
||||
type
|
||||
|
||||
{ TJLabeledFloatEdit }
|
||||
|
||||
TJLabeledFloatEdit = class(TCustomLabeledEdit)
|
||||
private
|
||||
{ Private declarations }
|
||||
theValue: double;
|
||||
fFormat: string;
|
||||
fDecimals: integer;
|
||||
function getDecimals: integer;
|
||||
function getFormat: string;
|
||||
function getValue: double;
|
||||
procedure formatInput;
|
||||
procedure setDecimals(const AValue: integer);
|
||||
procedure setFormat(const AValue: string);
|
||||
function scaleTo(const AValue: double; const NDecimals: integer): double;
|
||||
function IsValidFloat(const Value: string): boolean;
|
||||
procedure setValue(const AValue: double);
|
||||
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 }
|
||||
property DisplayFormat: string read getFormat write setFormat;
|
||||
property Decimals: integer read getDecimals write setDecimals;
|
||||
property Value: double 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 ReadOnly;
|
||||
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
|
||||
Math;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
{$I jlabeledfloatedit_icon.lrs}
|
||||
RegisterComponents('Additional', [TJLabeledFloatEdit]);
|
||||
end;
|
||||
|
||||
function TJLabeledFloatEdit.getDecimals: integer;
|
||||
begin
|
||||
Result := fDecimals;
|
||||
end;
|
||||
|
||||
function TJLabeledFloatEdit.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
function TJLabeledFloatEdit.getValue: double;
|
||||
begin
|
||||
Result := theValue;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.formatInput;
|
||||
begin
|
||||
Caption := FormatFloat(DisplayFormat, theValue);
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.setDecimals(const AValue: integer);
|
||||
begin
|
||||
if (AValue >= 0) and (AValue < 12) then
|
||||
fDecimals := AValue;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
function TJLabeledFloatEdit.scaleTo(const AValue: double;
|
||||
const NDecimals: integer): double;
|
||||
begin
|
||||
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
||||
end;
|
||||
|
||||
function TJLabeledFloatEdit.IsValidFloat(const Value: string): boolean;
|
||||
begin
|
||||
if StrToFloatDef(Value, MaxDouble) = MaxDouble then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.setValue(const AValue: double);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.DoEnter;
|
||||
begin
|
||||
inherited DoEnter;
|
||||
Text := FloatToStr(theValue);
|
||||
SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.DoExit;
|
||||
begin
|
||||
inherited DoExit;
|
||||
if IsValidFloat(Text) then
|
||||
theValue := StrToCurr(Text)
|
||||
else
|
||||
begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJLabeledFloatEdit.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 (fDecimals = 0) then
|
||||
Key := #0;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
constructor TJLabeledFloatEdit.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
Text := '';
|
||||
fFormat := '#,0.00';
|
||||
fDecimals := 2;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
destructor TJLabeledFloatEdit.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -0,0 +1,34 @@
|
||||
LazarusResources.Add('tjlabeledfloatedit','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#27#9
|
||||
+'/'#26#222#138#14';'#0#0#2#155'IDATH'#199#181'VOH'#147'a'#24#255#189#18'z'
|
||||
+#169'M,'#149'!K'#26'HBj'#200'^'#4'Y^'#182#131#18'A'#135']DIl'#228#165#14#210
|
||||
+'e"By'#9#217'%&x'#8'D'#172'C'#212#161#29#4#3'/'#187#228#188#200#23#129#127' '
|
||||
+#148'D'#29#171#248#16#219#180#192#141#182'_'#135'z?'#191#185'M'#167#185#7'^'
|
||||
+#222#231'yyy~'#239#251'{~'#239#243'}'#130'$Ji'#23#204#193#219#249'o'#152#156
|
||||
+#221#200#187'q'#224#142#3#221#29#182'S'#3#8#146'Y'#137#199#31#221'D'#211#213
|
||||
+#139'X'#217#254#9'='#158#132#158'HA'#143'''1'#19#137#157#9#168#12#0'&g7'#208
|
||||
+#210'P'#133#187#183#234#160#199#147#144'R'#210#156'\O'#164#208#210'P'#5#135
|
||||
+#221'R'#240#134'RJ'#22#4'p'#216'-XZ'#223#197'L$'#6#191#175#147#0#224#247'uR'
|
||||
+#143'''Q'#151#250#200#185'`'#15#231'_'#220'c'#151'm'#141#14#187'%+'#153#148
|
||||
+#146'*'#206#7'"Hb`b'#25#181#149#21#168#177#150'c&'#18'C"<H'#171'g\'#0'0'#252
|
||||
+#246#230'j'#204#5'{'#216#218'?-'#186'lk'#28#27#27#3#0#12#15#15#195#235#245#10
|
||||
+')%5M'#19'yo'#176#17#221'3'#22'Fz'#27#141'Z(?'#17#30#228'\'#176#135'j'#175
|
||||
+#215#235'5'#18#153#253#130'*r'#216'-X\'#221'A:C4'#213'7'#230'l'#234'{'#250'N'
|
||||
+#168'";'#236#22#132'B!'#131#138'P('#196#227'@'#10'R'#4#0'V'#207#184'x'#216
|
||||
+#246#221#160#3#0'Z'#251#167#197#167#151#247#13':'#20'5'#138#255#163'4'#9#146
|
||||
+#240#12'-'#160#189#185#26'5'#214'r4'#213'_'#130#187#229'r'#142'L'#245'D'#10
|
||||
+#191#14#210'XZ'#223'E8'#224':'#221';'#24#152'X'#198'Vl'#31#233#12'1'#210#219
|
||||
+#136'M'#237#253#185'<o'#159#175'O'#24'/'#185#237#198#21#212'X'#203#241#236
|
||||
+#245'g'#244'^'#7'V'#150#230#255'+'#249#232#232#147#195'"o'#197#246'Q[Ya'#168
|
||||
+'hS'#251#2#0'x'#30#156'<3'#192'^<z(S'#223#237'kX\'#221'1'#218#129#217'<C'#11
|
||||
+'9'#177'Z'#251#157#206'd'#197'R'#202#172#25#0'@'#210#24'o>|'#133#219#31#193
|
||||
+#212#212'+>'#30'|@'#146't'#251'#'#204'gn'#127#132#153'L&+&I'#167#211'I'#146
|
||||
+'L'#252#216'&'#201#191'7P'#214#221'a;Q!G'#219#187':\Q'#237#250#164#196'B'#8
|
||||
+#131'&u'#16'EO'#161#131#149#21#173#231#127#201#213#172'@'#195#1#23#194#1'WN'
|
||||
+#173'N'#13'`.'#178':'#173#25#236#216#239'A'#177#137#243')I'#249#225#128#11'R'
|
||||
+'Jh'#154'VXEj'#152'UtT%'#197#154'R'#145#200#167#128#189'x'#244'\Z'#133#165
|
||||
+#210'.D'#169#255'*'#202'Pb'#251#3#3#157#217#235'>i'#220'Y'#0#0#0#0'IEND'#174
|
||||
+'B`'#130
|
||||
]);
|
Reference in New Issue
Block a user