You've already forked lazarus-ccr
Implemented: NegativeDisplayFormat and NegativeColor to JLabeledCurrencyEdit
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5629 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -32,17 +32,23 @@ type
|
|||||||
TJLabeledCurrencyEdit = class(TCustomLabeledEdit)
|
TJLabeledCurrencyEdit = class(TCustomLabeledEdit)
|
||||||
private
|
private
|
||||||
fEFormat: string;
|
fEFormat: string;
|
||||||
|
fNColor: TColor;
|
||||||
|
fPColor: TColor;
|
||||||
theValue: currency;
|
theValue: currency;
|
||||||
fFormat: string;
|
fFormat: string;
|
||||||
|
fNFormat: string;
|
||||||
fDecimals: integer;
|
fDecimals: integer;
|
||||||
function getDecimals: integer;
|
function getDecimals: integer;
|
||||||
function getFormat: string;
|
function getFormat: string;
|
||||||
|
function getNegativeFormat: string;
|
||||||
function getValue: currency;
|
function getValue: currency;
|
||||||
procedure formatInput;
|
procedure formatInput;
|
||||||
procedure setDecimals(const AValue: integer);
|
procedure setDecimals(const AValue: integer);
|
||||||
procedure setFormat(const AValue: string);
|
procedure setFormat(const AValue: string);
|
||||||
function scaleTo(const AValue: currency; const NDecimals: integer): currency;
|
function scaleTo(const AValue: currency; const NDecimals: integer): currency;
|
||||||
function IsValidFloat(const Value: string): boolean;
|
function IsValidFloat(const Value: string): boolean;
|
||||||
|
procedure setNegativeColor(AValue: TColor);
|
||||||
|
procedure setNegativeFormat(AValue: string);
|
||||||
procedure setValue(const AValue: currency);
|
procedure setValue(const AValue: currency);
|
||||||
protected
|
protected
|
||||||
{ Protected declarations }
|
{ Protected declarations }
|
||||||
@ -59,6 +65,9 @@ type
|
|||||||
property EditFormat: string read fEFormat write fEFormat;
|
property EditFormat: string read fEFormat write fEFormat;
|
||||||
property Decimals: integer read getDecimals write setDecimals;
|
property Decimals: integer read getDecimals write setDecimals;
|
||||||
property Value: currency read getValue write setValue;
|
property Value: currency read getValue write setValue;
|
||||||
|
property NegativeDisplayFormat: string read getNegativeFormat
|
||||||
|
write setNegativeFormat;
|
||||||
|
property NegativeColor: TColor read fNColor write setNegativeColor;
|
||||||
|
|
||||||
property Action;
|
property Action;
|
||||||
property Align;
|
property Align;
|
||||||
@ -134,6 +143,11 @@ begin
|
|||||||
Result := fFormat;
|
Result := fFormat;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJLabeledCurrencyEdit.getNegativeFormat: string;
|
||||||
|
begin
|
||||||
|
Result := fNFormat;
|
||||||
|
end;
|
||||||
|
|
||||||
function TJLabeledCurrencyEdit.getValue: currency;
|
function TJLabeledCurrencyEdit.getValue: currency;
|
||||||
begin
|
begin
|
||||||
Result := theValue;
|
Result := theValue;
|
||||||
@ -141,7 +155,19 @@ end;
|
|||||||
|
|
||||||
procedure TJLabeledCurrencyEdit.formatInput;
|
procedure TJLabeledCurrencyEdit.formatInput;
|
||||||
begin
|
begin
|
||||||
|
if Font.Color <> fNColor then
|
||||||
|
fPColor := Font.Color; // store original font color
|
||||||
|
if (theValue < 0) and (fNFormat <> '') then
|
||||||
|
begin
|
||||||
|
Caption := FormatFloat(fNFormat, -theValue);
|
||||||
|
font.Color := fNColor;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
Caption := FormatFloat(DisplayFormat, theValue);
|
Caption := FormatFloat(DisplayFormat, theValue);
|
||||||
|
font.Color := fPColor;
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJLabeledCurrencyEdit.setDecimals(const AValue: integer);
|
procedure TJLabeledCurrencyEdit.setDecimals(const AValue: integer);
|
||||||
@ -170,6 +196,20 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TJLabeledCurrencyEdit.setNegativeColor(AValue: TColor);
|
||||||
|
begin
|
||||||
|
if fNColor = AValue then
|
||||||
|
Exit;
|
||||||
|
fNColor := AValue;
|
||||||
|
formatInput;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJLabeledCurrencyEdit.setNegativeFormat(AValue: string);
|
||||||
|
begin
|
||||||
|
fNFormat := AValue;
|
||||||
|
formatInput;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TJLabeledCurrencyEdit.setValue(const AValue: currency);
|
procedure TJLabeledCurrencyEdit.setValue(const AValue: currency);
|
||||||
begin
|
begin
|
||||||
if fDecimals > 0 then
|
if fDecimals > 0 then
|
||||||
@ -228,6 +268,8 @@ begin
|
|||||||
Text := '';
|
Text := '';
|
||||||
fFormat := '#,0.00';
|
fFormat := '#,0.00';
|
||||||
fDecimals := 2;
|
fDecimals := 2;
|
||||||
|
fPColor := Font.Color;
|
||||||
|
fNColor := Font.Color;
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user