You've already forked lazarus-ccr
Remove old example code
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2028 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,155 +0,0 @@
|
||||
{ jcontrolutils
|
||||
|
||||
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 jcontrolutils;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Dialogs;
|
||||
|
||||
function CountChar(const s: string; ch: char): integer;
|
||||
procedure Split(const Delimiter: char; Input: string; Strings: TStrings);
|
||||
function NormalizeDate(const Value: string; theValue: TDateTime;
|
||||
const theFormat: string = ''): string;
|
||||
function NormalizeDateSeparator(const s: string): string;
|
||||
function IsValidDateString(const Value: string): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function CountChar(const s: string; ch: char): integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
for i := 1 to length(s) do
|
||||
if s[i] = ch then
|
||||
Inc(Result);
|
||||
end;
|
||||
|
||||
procedure Split(const Delimiter: char; Input: string; Strings: TStrings);
|
||||
begin
|
||||
Assert(Assigned(Strings));
|
||||
Strings.Clear;
|
||||
Strings.Delimiter := Delimiter;
|
||||
Strings.DelimitedText := Input;
|
||||
end;
|
||||
|
||||
function NormalizeDate(const Value: string; theValue: TDateTime;
|
||||
const theFormat: string): string;
|
||||
var
|
||||
texto: string;
|
||||
i: integer;
|
||||
d, m, y: word;
|
||||
ds, ms, ys: string;
|
||||
aDate: TDateTime;
|
||||
tokens: TStringList;
|
||||
aDateFormat: string;
|
||||
aChar: char;
|
||||
|
||||
procedure LittleEndianForm;
|
||||
begin
|
||||
// Note: only numeric input allowed (months names not implemented)
|
||||
if tokens[0] <> '' then
|
||||
ds := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ms := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ys := tokens[2];
|
||||
texto := ds + DateSeparator + ms + DateSeparator + ys;
|
||||
end;
|
||||
|
||||
procedure MiddleEndianForm;
|
||||
begin
|
||||
if tokens[0] <> '' then
|
||||
ms := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ds := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ys := tokens[2];
|
||||
texto := ms + DateSeparator + ds + DateSeparator + ys;
|
||||
end;
|
||||
|
||||
procedure BigEndianForm;
|
||||
begin
|
||||
if tokens[0] <> '' then
|
||||
ys := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ms := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ds := tokens[2];
|
||||
texto := ys + DateSeparator + ms + DateSeparator + ds;
|
||||
end;
|
||||
|
||||
begin
|
||||
if theFormat = '' then
|
||||
aDateFormat := ShortDateFormat
|
||||
else
|
||||
aDateFormat := theFormat;
|
||||
if theValue = 0 then
|
||||
DecodeDate(Now, y, m, d)
|
||||
else
|
||||
decodedate(theValue, y, m, d);
|
||||
ds := IntToStr(d);
|
||||
ms := IntToStr(m);
|
||||
ys := IntToStr(y);
|
||||
texto := Value;
|
||||
texto := NormalizeDateSeparator(texto);
|
||||
Result := texto; // default value
|
||||
i := countchar(texto, DateSeparator);
|
||||
tokens := TStringList.Create;
|
||||
Split(DateSeparator, texto, tokens);
|
||||
if tokens.Count > 0 then
|
||||
begin
|
||||
aChar := aDateFormat[1];
|
||||
case aChar of
|
||||
'd', 'D': LittleEndianForm;
|
||||
'm', 'M': MiddleEndianForm;
|
||||
'y', 'Y': BigEndianForm;
|
||||
end;
|
||||
|
||||
if IsValidDateString(texto) then
|
||||
begin
|
||||
aDate := StrToDate(texto);
|
||||
Result := FormatDateTime(aDateFormat, aDate);
|
||||
end;
|
||||
end;
|
||||
tokens.Free;
|
||||
end;
|
||||
|
||||
function NormalizeDateSeparator(const s: string): string;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
Result := s;
|
||||
for i := 1 to length(Result) do
|
||||
if Result[i] in ['.', ',', '/', '-'] then // valid date separators
|
||||
Result[i] := DateSeparator;
|
||||
end;
|
||||
|
||||
function IsValidDateString(const Value: string): boolean;
|
||||
begin
|
||||
if StrToDateDef(Value, MaxDateTime) = MaxDateTime then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1,505 +0,0 @@
|
||||
{ jdbgridutils
|
||||
|
||||
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 jdbgridutils;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Grids, Dialogs, LCLType, DBGrids, Controls, DB,
|
||||
jcontrolutils;
|
||||
|
||||
type
|
||||
|
||||
{ TJDbGridDateCtrl }
|
||||
|
||||
TJDbGridDateCtrl = class(TObject)
|
||||
private
|
||||
Field: TField;
|
||||
updated: boolean;
|
||||
theValue: TDateTime;
|
||||
fFormat: string;
|
||||
function getFormat: string;
|
||||
procedure myEditEnter(Sender: TObject);
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
procedure formatInput;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
||||
public
|
||||
CellEditor: TStringCellEditor;
|
||||
theGrid: TDBGrid;
|
||||
function isNull: boolean;
|
||||
property format: string read getFormat write setFormat;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
end;
|
||||
|
||||
{ TJDbGridIntegerCtrl }
|
||||
|
||||
TJDbGridIntegerCtrl = class(TObject)
|
||||
private
|
||||
theValue: integer;
|
||||
updated: boolean;
|
||||
Field: TField;
|
||||
procedure myEditOnEnter(Sender: TObject);
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
function IsValidInteger(const Value: string): boolean;
|
||||
public
|
||||
CellEditor: TStringCellEditor;
|
||||
theGrid: TDBGrid;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
end;
|
||||
|
||||
{ TJDbGridCurrencyCtrl }
|
||||
|
||||
TJDbGridCurrencyCtrl = class(TObject)
|
||||
private
|
||||
Field: TField;
|
||||
updated: boolean;
|
||||
theValue: currency;
|
||||
fDecimales: integer;
|
||||
function getDecimales: integer;
|
||||
procedure myEditOnEnter(Sender: TObject);
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
procedure setDecimales(const AValue: integer);
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
||||
function redondear(const AValue: currency; const NDecimales: integer): currency;
|
||||
function IsValidFloat(const Value: string): boolean;
|
||||
public
|
||||
CellEditor: TStringCellEditor;
|
||||
theGrid: TDBGrid;
|
||||
property decimales: integer read getDecimales write setDecimales;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Editor(aGrid: TDBGrid; aDecimals: integer = 2): TStringCellEditor;
|
||||
end;
|
||||
|
||||
var
|
||||
dateDbGridControl: TJDbGridDateCtrl;
|
||||
integerDbGridControl: TJDbGridIntegerCtrl;
|
||||
currencyDbGridControl: TJDbGridCurrencyCtrl;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math, dateutils;
|
||||
|
||||
{ TJDbGridDateCtrl }
|
||||
|
||||
function TJDbGridDateCtrl.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.myEditEnter(Sender: TObject);
|
||||
begin
|
||||
Field := theGrid.SelectedField;
|
||||
CellEditor.BoundsRect := theGrid.SelectedFieldRect;
|
||||
CellEditor.Text := Field.AsString;
|
||||
CellEditor.OnKeyPress := @OnKeyPress; // Recuperamos el control :-p
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
theValue := Field.AsDateTime;
|
||||
updated := False;
|
||||
CellEditor.SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
begin
|
||||
CellEditor.Caption:= NormalizeDate(CellEditor.Caption, theValue);
|
||||
if Length(CellEditor.Caption) = 0 then
|
||||
theValue := 0
|
||||
else
|
||||
if IsValidDateString(CellEditor.Caption) then
|
||||
begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToDate(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsDateTime := theValue;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es una fecha válida');
|
||||
CellEditor.Text := FormatDateTime(format, theValue);
|
||||
end;
|
||||
//formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.formatInput;
|
||||
begin
|
||||
if theValue <> 0 then
|
||||
CellEditor.Caption := FormatDateTime(format, theValue);
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, '.', '-', '/']) then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
procedure TJDbGridDateCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
if Length(CellEditor.Caption) <> 0 then
|
||||
if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and
|
||||
(not IsValidDateString(NormalizeDate(CellEditor.Caption, theValue))) then
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es una fecha válida');
|
||||
CellEditor.Text := FormatDateTime(format, theValue);
|
||||
CellEditor.SelectAll;
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if key = VK_ESCAPE then
|
||||
begin
|
||||
if Field.IsNull then
|
||||
CellEditor.Text := ''
|
||||
else
|
||||
CellEditor.Text := FormatDateTime(format, Field.AsDateTime);
|
||||
updated := True;
|
||||
theGrid.SetFocus; // No perder el foco
|
||||
end
|
||||
else
|
||||
if Key in [VK_UP, VK_DOWN] then
|
||||
begin
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if Key in [VK_RETURN, VK_TAB, VK_RIGHT, VK_LEFT] then
|
||||
begin
|
||||
CellEditor.Caption:= NormalizeDate(CellEditor.Caption, theValue);
|
||||
if Length(CellEditor.Caption) = 0 then
|
||||
theValue := 0
|
||||
else
|
||||
if IsValidDateString(CellEditor.Caption) then
|
||||
begin
|
||||
theValue := StrToDate(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsDateTime := theValue;
|
||||
CellEditor.SelectAll;
|
||||
updated := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TJDbGridDateCtrl.isNull: boolean;
|
||||
begin
|
||||
Result := theValue = 0;
|
||||
end;
|
||||
|
||||
constructor TJDbGridDateCtrl.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
CellEditor := TStringCellEditor.Create(nil);
|
||||
CellEditor.OnEnter := @myEditEnter;
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
CellEditor.OnEditingDone := @myEditOnEditingDone;
|
||||
CellEditor.OnKeyPress := @OnKeyPress; // se sobreescribe por el Grid :(
|
||||
format := ShortDateFormat;
|
||||
end;
|
||||
|
||||
destructor TJDbGridDateCtrl.Destroy;
|
||||
begin
|
||||
CellEditor.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TJDbGridDateCtrl.Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
begin
|
||||
theGrid := aGrid;
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
{ TJDbGridCurrencyCtrl }
|
||||
|
||||
function TJDbGridCurrencyCtrl.getDecimales: integer;
|
||||
begin
|
||||
Result := fDecimales;
|
||||
end;
|
||||
|
||||
procedure TJDbGridCurrencyCtrl.myEditOnEnter(Sender: TObject);
|
||||
begin
|
||||
Field := theGrid.SelectedField;
|
||||
CellEditor.BoundsRect := theGrid.SelectedFieldRect;
|
||||
CellEditor.Text := Field.AsString;
|
||||
CellEditor.OnKeyPress := @OnKeyPress; // Recuperamos el control :-p
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
theValue := Field.AsCurrency;
|
||||
updated := False;
|
||||
CellEditor.SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJDbGridCurrencyCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
begin
|
||||
if IsValidFloat(CellEditor.Caption) then
|
||||
begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToCurr(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
theValue := redondear(theValue, fDecimales);
|
||||
Field.AsCurrency := theValue;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es un número válido');
|
||||
CellEditor.Text := FloatToStr(theValue);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDbGridCurrencyCtrl.setDecimales(const AValue: integer);
|
||||
begin
|
||||
if (AValue >= 0) and (AValue < 5) then
|
||||
fDecimales := AValue;
|
||||
end;
|
||||
|
||||
procedure TJDbGridCurrencyCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if (Key in ['.', ',']) then
|
||||
Key := Decimalseparator;
|
||||
if (key = DecimalSeparator) and (Pos(key, CellEditor.Caption) > 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;
|
||||
end;
|
||||
|
||||
procedure TJDbGridCurrencyCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and
|
||||
(not IsValidFloat(CellEditor.Caption)) then
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es número válido');
|
||||
CellEditor.Text := FloatToStr(theValue);
|
||||
CellEditor.SelectAll;
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if key = VK_ESCAPE then
|
||||
begin
|
||||
if Field.IsNull then
|
||||
CellEditor.Text := ''
|
||||
else
|
||||
CellEditor.Text := CurrToStr(redondear(Field.AsCurrency, fDecimales));
|
||||
updated:= True;
|
||||
theGrid.SetFocus; // No perder el foco
|
||||
end
|
||||
else
|
||||
if key in [VK_UP, VK_DOWN] then
|
||||
begin
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if Key in [VK_RETURN, VK_TAB] then
|
||||
begin
|
||||
if IsValidFloat(CellEditor.Caption) then
|
||||
begin
|
||||
theValue := StrToCurr(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsCurrency := redondear(theValue, fDecimales);
|
||||
CellEditor.Text:= Field.AsString;
|
||||
updated := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJDbGridCurrencyCtrl.redondear(const AValue: currency;
|
||||
const NDecimales: integer): currency;
|
||||
begin
|
||||
redondear := round(AValue * power(10, NDecimales)) / power(10, NDecimales);
|
||||
end;
|
||||
|
||||
function TJDbGridCurrencyCtrl.IsValidFloat(const Value: string): boolean;
|
||||
begin
|
||||
if StrToCurrDef(Value, MaxCurrency) = MaxCurrency then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
constructor TJDbGridCurrencyCtrl.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
CellEditor := TStringCellEditor.Create(nil);
|
||||
CellEditor.OnEnter := @myEditOnEnter;
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
CellEditor.OnEditingDone := @myEditOnEditingDone;
|
||||
fDecimales := 2;
|
||||
end;
|
||||
|
||||
destructor TJDbGridCurrencyCtrl.Destroy;
|
||||
begin
|
||||
CellEditor.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TJDbGridCurrencyCtrl.Editor(aGrid: TDBGrid;
|
||||
aDecimals: integer): TStringCellEditor;
|
||||
begin
|
||||
decimales := aDecimals;
|
||||
theGrid := aGrid;
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
{ TJDbGridIntegerCtrl }
|
||||
|
||||
procedure TJDbGridIntegerCtrl.myEditOnEnter(Sender: TObject);
|
||||
begin
|
||||
Field := theGrid.SelectedField;
|
||||
CellEditor.BoundsRect := theGrid.SelectedFieldRect;
|
||||
CellEditor.Text := Field.AsString;
|
||||
CellEditor.OnKeyPress := @OnKeyPress; // Recuperamos el control :-p
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
theValue := Field.AsInteger;
|
||||
CellEditor.SelectAll;
|
||||
updated := False;
|
||||
end;
|
||||
|
||||
procedure TJDbGridIntegerCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, '-']) then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
procedure TJDbGridIntegerCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and
|
||||
(not IsValidInteger(CellEditor.Caption)) then
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es un número válido');
|
||||
CellEditor.Text := IntToStr(theValue);
|
||||
CellEditor.SelectAll;
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if (Key = VK_ESCAPE) then
|
||||
begin
|
||||
if Field.IsNull then
|
||||
CellEditor.Text := ''
|
||||
else
|
||||
CellEditor.Text := IntToStr(Field.AsInteger);
|
||||
updated := True;
|
||||
theGrid.SetFocus; // No perder el foco
|
||||
end
|
||||
else
|
||||
if key in [VK_UP, VK_DOWN] then
|
||||
begin
|
||||
Key := VK_UNKNOWN;
|
||||
end
|
||||
else
|
||||
if Key in [VK_RETURN, VK_TAB] then
|
||||
begin
|
||||
if IsValidInteger(CellEditor.Caption) then
|
||||
begin
|
||||
theValue := StrToInt(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsInteger := theValue;
|
||||
updated := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJDbGridIntegerCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
begin
|
||||
if IsValidInteger(CellEditor.Caption) then
|
||||
begin
|
||||
if (not updated) then
|
||||
begin
|
||||
theValue := StrToInt(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsInteger := theValue;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
ShowMessage(CellEditor.Caption + ' no es un número válido');
|
||||
CellEditor.Text := IntToStr(theValue);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJDbGridIntegerCtrl.IsValidInteger(const Value: string): boolean;
|
||||
begin
|
||||
if StrToIntDef(Value, MaxInt) = MaxInt then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
constructor TJDbGridIntegerCtrl.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
CellEditor := TStringCellEditor.Create(nil);
|
||||
CellEditor.OnEnter := @myEditOnEnter;
|
||||
CellEditor.OnKeyDown := @OnKeyDown;
|
||||
CellEditor.OnEditingDone := @myEditOnEditingDone;
|
||||
CellEditor.OnKeyPress := @OnKeyPress; // se sobreescribe por el Grid :(
|
||||
end;
|
||||
|
||||
destructor TJDbGridIntegerCtrl.Destroy;
|
||||
begin
|
||||
CellEditor.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TJDbGridIntegerCtrl.Editor(aGrid: TDBGrid): TStringCellEditor;
|
||||
begin
|
||||
theGrid := aGrid;
|
||||
Result := CellEditor;
|
||||
end;
|
||||
|
||||
procedure CreateResources;
|
||||
begin
|
||||
dateDbGridControl := TJDbGridDateCtrl.Create;
|
||||
integerDbGridControl := TJDbGridIntegerCtrl.Create;
|
||||
currencyDbGridControl := TJDbGridCurrencyCtrl.Create;
|
||||
end;
|
||||
|
||||
procedure CleanResources;
|
||||
begin
|
||||
dateDbGridControl.Free;
|
||||
integerDbGridControl.Free;
|
||||
currencyDbGridControl.Free;
|
||||
end;
|
||||
|
||||
initialization
|
||||
CreateResources;
|
||||
|
||||
finalization
|
||||
CleanResources;
|
||||
end.
|
||||
|
@ -1,312 +0,0 @@
|
||||
{ jdbutils
|
||||
|
||||
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 jdbutils;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, DBCtrls, jcontrolutils;
|
||||
|
||||
type
|
||||
|
||||
{ TJDBCurrencyCtrl }
|
||||
|
||||
TJDBCurrencyCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TDBEdit;
|
||||
theValue: currency;
|
||||
fDecimales: integer;
|
||||
function getDecimales: integer;
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
procedure setDecimales(const AValue: integer);
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
function redondear(const AValue: currency; const NDecimales: integer): currency;
|
||||
function IsValidFloat(const Value: string): boolean;
|
||||
public
|
||||
property decimales: integer read getDecimales write setDecimales;
|
||||
procedure Enter(widget: TDBEdit);
|
||||
end;
|
||||
|
||||
{ TJDBIntegerCtrl }
|
||||
|
||||
TJDBIntegerCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TDBEdit;
|
||||
theValue: integer;
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
function IsValidInteger(const Value: string): boolean;
|
||||
public
|
||||
procedure Enter(widget: TDBEdit);
|
||||
end;
|
||||
|
||||
{ TJDBDateCtrl }
|
||||
|
||||
TJDBDateCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TDBEdit;
|
||||
theValue: TDateTime;
|
||||
fFormat: string;
|
||||
function getFormat: string;
|
||||
procedure myEditOnEditingDone(Sender: TObject);
|
||||
procedure formatInput;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||
public
|
||||
function isNull: boolean;
|
||||
property format: string read getFormat write setFormat;
|
||||
procedure Enter(widget: TDBEdit);
|
||||
end;
|
||||
|
||||
var
|
||||
dateDbControl: TJDBDateCtrl;
|
||||
integerDbControl: TJDBIntegerCtrl;
|
||||
currencyDbControl: TJDBCurrencyCtrl;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math, dateutils, Graphics, Dialogs;
|
||||
|
||||
|
||||
{ TJDBCurrencyCtrl }
|
||||
|
||||
function TJDBCurrencyCtrl.getDecimales: integer;
|
||||
begin
|
||||
Result := fDecimales;
|
||||
end;
|
||||
|
||||
procedure TJDBCurrencyCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
var
|
||||
bufCaption: string;
|
||||
begin
|
||||
if IsValidFloat(myEdit.Caption) then
|
||||
begin
|
||||
theValue := StrToCurr(myEdit.Caption);
|
||||
theValue := redondear(theValue, fDecimales);
|
||||
myEdit.Caption := CurrToStr(theValue);
|
||||
end
|
||||
else
|
||||
begin
|
||||
bufCaption := myEdit.Caption;
|
||||
myEdit.Caption := myEdit.Field.AsString;
|
||||
ShowMessage(bufCaption + ' no es un número válido');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TJDBCurrencyCtrl.setDecimales(const AValue: integer);
|
||||
begin
|
||||
if AValue >= 0 then
|
||||
fDecimales := AValue;
|
||||
end;
|
||||
|
||||
|
||||
procedure TJDBCurrencyCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if (Key in ['.', ',']) then
|
||||
Key := Decimalseparator;
|
||||
if (key = DecimalSeparator) and (Pos(key, myEdit.Caption) > 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;
|
||||
end;
|
||||
|
||||
function TJDBCurrencyCtrl.redondear(const AValue: currency;
|
||||
const NDecimales: integer): currency;
|
||||
begin
|
||||
redondear := round(AValue * power(10, NDecimales)) / power(10, NDecimales);
|
||||
end;
|
||||
|
||||
function TJDBCurrencyCtrl.IsValidFloat(const Value: string): boolean;
|
||||
begin
|
||||
if StrToCurrDef(Value, MaxCurrency) = MaxCurrency then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
|
||||
procedure TJDBCurrencyCtrl.Enter(widget: TDBEdit);
|
||||
begin
|
||||
myEdit := widget;
|
||||
if myEdit.DataSource.DataSet.Active then
|
||||
begin
|
||||
myEdit.OnEditingDone := @myEditOnEditingDone;
|
||||
myEdit.OnKeyPress := @OnKeyPress;
|
||||
fDecimales := 2; // default 2 decimals
|
||||
theValue := myEdit.Field.AsCurrency;
|
||||
myEdit.SelectAll;
|
||||
end
|
||||
else
|
||||
begin
|
||||
myEdit.OnEditingDone := nil;
|
||||
myEdit.OnKeyPress := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TJDBIntegerCtrl }
|
||||
|
||||
procedure TJDBIntegerCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, '-']) then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
procedure TJDBIntegerCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
var
|
||||
bufCaption: string;
|
||||
begin
|
||||
if IsValidInteger(myEdit.Caption) then
|
||||
begin
|
||||
theValue := StrToInt(myEdit.Caption);
|
||||
myEdit.Caption := IntToStr(theValue);
|
||||
end
|
||||
else
|
||||
begin
|
||||
bufCaption := myEdit.Caption;
|
||||
myEdit.Caption := myEdit.Field.AsString;
|
||||
ShowMessage(bufCaption + ' no es un número válido');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJDBIntegerCtrl.IsValidInteger(const Value: string): boolean;
|
||||
begin
|
||||
if StrToIntDef(Value, MaxInt) = MaxInt then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJDBIntegerCtrl.Enter(widget: TDBEdit);
|
||||
begin
|
||||
myEdit := widget;
|
||||
if myEdit.DataSource.DataSet.Active then
|
||||
begin
|
||||
myEdit.OnEditingDone := @myEditOnEditingDone;
|
||||
myEdit.OnKeyPress := @OnKeyPress;
|
||||
theValue := myEdit.Field.AsInteger;
|
||||
myEdit.SelectAll;
|
||||
end
|
||||
else
|
||||
begin
|
||||
myEdit.OnEditingDone := nil;
|
||||
myEdit.OnKeyPress := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TJDBDateCtrl }
|
||||
|
||||
function TJDBDateCtrl.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
procedure TJDBDateCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
var
|
||||
bufCaption: string;
|
||||
begin
|
||||
bufCaption := NormalizeDate(myEdit.Caption, theValue);
|
||||
if Length(myEdit.Caption) = 0 then
|
||||
theValue := 0
|
||||
else
|
||||
if IsValidDateString(bufCaption) then
|
||||
begin
|
||||
theValue := StrToDate(bufCaption);
|
||||
myEdit.Caption := bufCaption;
|
||||
end
|
||||
else
|
||||
begin
|
||||
myEdit.Caption := myEdit.Field.AsString;
|
||||
ShowMessage(bufCaption + ' no es una fecha válida');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
//formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDBDateCtrl.formatInput;
|
||||
begin
|
||||
if theValue <> 0 then
|
||||
myEdit.Caption := FormatDateTime(format, theValue);
|
||||
end;
|
||||
|
||||
procedure TJDBDateCtrl.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDBDateCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9', #8, #9, '.', '-', '/']) then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
function TJDBDateCtrl.isNull: boolean;
|
||||
begin
|
||||
Result := theValue = 0;
|
||||
end;
|
||||
|
||||
procedure TJDBDateCtrl.Enter(widget: TDBEdit);
|
||||
begin
|
||||
myEdit := widget;
|
||||
if myEdit.DataSource.DataSet.Active then
|
||||
begin
|
||||
myEdit.OnEditingDone := @myEditOnEditingDone;
|
||||
myEdit.OnKeyPress := @OnKeyPress;
|
||||
format := ShortDateFormat;
|
||||
theValue := myEdit.Field.AsDateTime;
|
||||
myEdit.SelectAll;
|
||||
end
|
||||
else
|
||||
begin
|
||||
myEdit.OnEditingDone := nil;
|
||||
myEdit.OnKeyPress := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure CreateResources;
|
||||
begin
|
||||
dateDbControl := TJDBDateCtrl.Create;
|
||||
integerDbControl := TJDBIntegerCtrl.Create;
|
||||
currencyDbControl := TJDBCurrencyCtrl.Create;
|
||||
end;
|
||||
|
||||
procedure CleanResources;
|
||||
begin
|
||||
dateDbControl.Free;
|
||||
integerDbControl.Free;
|
||||
currencyDbControl.Free;
|
||||
end;
|
||||
|
||||
initialization
|
||||
CreateResources;
|
||||
|
||||
finalization
|
||||
CleanResources;
|
||||
end.
|
||||
|
@ -1,193 +0,0 @@
|
||||
object Form1: TForm1
|
||||
Left = 285
|
||||
Height = 435
|
||||
Top = 159
|
||||
Width = 500
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 435
|
||||
ClientWidth = 500
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '0.9.31'
|
||||
object DBGrid1: TDBGrid
|
||||
Left = 26
|
||||
Height = 153
|
||||
Top = 119
|
||||
Width = 416
|
||||
Color = clWindow
|
||||
Columns = <
|
||||
item
|
||||
Title.Caption = 'ID'
|
||||
Title.PrefixOption = poNone
|
||||
FieldName = 'ID'
|
||||
end
|
||||
item
|
||||
Title.Caption = 'DATE'
|
||||
Title.PrefixOption = poNone
|
||||
FieldName = 'DATE'
|
||||
DisplayFormat = 'dd/mm/yyyy'
|
||||
end
|
||||
item
|
||||
Title.Caption = 'ID2'
|
||||
Title.PrefixOption = poNone
|
||||
FieldName = 'ID2'
|
||||
end
|
||||
item
|
||||
Title.Caption = 'TOTAL'
|
||||
Title.PrefixOption = poNone
|
||||
FieldName = 'TOTAL'
|
||||
DisplayFormat = '#,0.00'
|
||||
end>
|
||||
DataSource = Datasource1
|
||||
TabOrder = 0
|
||||
OnSelectEditor = DBGrid1SelectEditor
|
||||
end
|
||||
object DBNavigator1: TDBNavigator
|
||||
Left = 26
|
||||
Height = 25
|
||||
Top = 87
|
||||
Width = 241
|
||||
BevelOuter = bvNone
|
||||
ChildSizing.EnlargeHorizontal = crsScaleChilds
|
||||
ChildSizing.EnlargeVertical = crsScaleChilds
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 100
|
||||
ClientHeight = 25
|
||||
ClientWidth = 241
|
||||
DataSource = Datasource1
|
||||
Options = []
|
||||
TabOrder = 1
|
||||
end
|
||||
object GroupBox1: TGroupBox
|
||||
Left = 24
|
||||
Height = 105
|
||||
Top = 280
|
||||
Width = 418
|
||||
Caption = 'TDBEdit usage example'
|
||||
ClientHeight = 86
|
||||
ClientWidth = 414
|
||||
TabOrder = 2
|
||||
object Label1: TLabel
|
||||
Left = 14
|
||||
Height = 18
|
||||
Top = 7
|
||||
Width = 15
|
||||
Caption = 'ID'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
Left = 102
|
||||
Height = 18
|
||||
Top = 7
|
||||
Width = 31
|
||||
Caption = 'DATE'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label3: TLabel
|
||||
Left = 195
|
||||
Height = 18
|
||||
Top = 7
|
||||
Width = 22
|
||||
Caption = 'ID2'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label4: TLabel
|
||||
Left = 288
|
||||
Height = 18
|
||||
Top = 9
|
||||
Width = 39
|
||||
Caption = 'TOTAL'
|
||||
ParentColor = False
|
||||
end
|
||||
object DBEdit1: TDBEdit
|
||||
Left = 14
|
||||
Height = 27
|
||||
Top = 31
|
||||
Width = 80
|
||||
DataField = 'ID'
|
||||
DataSource = Datasource1
|
||||
CharCase = ecNormal
|
||||
MaxLength = 0
|
||||
TabOrder = 0
|
||||
OnEnter = OnIntegerDBControlEnter
|
||||
end
|
||||
object DBEdit2: TDBEdit
|
||||
Left = 102
|
||||
Height = 27
|
||||
Top = 31
|
||||
Width = 80
|
||||
DataField = 'DATE'
|
||||
DataSource = Datasource1
|
||||
CharCase = ecNormal
|
||||
MaxLength = 0
|
||||
TabOrder = 1
|
||||
OnEnter = OnDateDBControlEnter
|
||||
end
|
||||
object DBEdit3: TDBEdit
|
||||
Left = 195
|
||||
Height = 27
|
||||
Top = 31
|
||||
Width = 80
|
||||
DataField = 'ID2'
|
||||
DataSource = Datasource1
|
||||
CharCase = ecNormal
|
||||
MaxLength = 0
|
||||
TabOrder = 2
|
||||
OnEnter = OnIntegerDBControlEnter
|
||||
end
|
||||
object DBEdit4: TDBEdit
|
||||
Left = 288
|
||||
Height = 27
|
||||
Top = 31
|
||||
Width = 80
|
||||
DataField = 'TOTAL'
|
||||
DataSource = Datasource1
|
||||
CharCase = ecNormal
|
||||
MaxLength = 0
|
||||
TabOrder = 3
|
||||
OnEnter = OnCurrencyDBControlEnter
|
||||
end
|
||||
end
|
||||
object Label5: TLabel
|
||||
Left = 24
|
||||
Height = 18
|
||||
Top = 56
|
||||
Width = 142
|
||||
Caption = 'TDBGrid usage example'
|
||||
ParentColor = False
|
||||
end
|
||||
object MemDataset1: TMemDataset
|
||||
Active = True
|
||||
FieldDefs = <
|
||||
item
|
||||
Name = 'ID'
|
||||
DataType = ftInteger
|
||||
Precision = 0
|
||||
Size = 0
|
||||
end
|
||||
item
|
||||
Name = 'DATE'
|
||||
DataType = ftDate
|
||||
Precision = 0
|
||||
Size = 0
|
||||
end
|
||||
item
|
||||
Name = 'TOTAL'
|
||||
DataType = ftFloat
|
||||
Precision = 0
|
||||
Size = 0
|
||||
end
|
||||
item
|
||||
Name = 'ID2'
|
||||
DataType = ftInteger
|
||||
Precision = 0
|
||||
Size = 0
|
||||
end>
|
||||
left = 40
|
||||
end
|
||||
object Datasource1: TDatasource
|
||||
DataSet = MemDataset1
|
||||
left = 128
|
||||
end
|
||||
end
|
@ -1,94 +0,0 @@
|
||||
unit main;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, memds, DB, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||
DBGrids, DBCtrls, StdCtrls, LCLType, jdbgridutils, jdbutils;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Datasource1: TDatasource;
|
||||
DBEdit1: TDBEdit;
|
||||
DBEdit2: TDBEdit;
|
||||
DBEdit3: TDBEdit;
|
||||
DBEdit4: TDBEdit;
|
||||
DBGrid1: TDBGrid;
|
||||
DBNavigator1: TDBNavigator;
|
||||
GroupBox1: TGroupBox;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Label3: TLabel;
|
||||
Label4: TLabel;
|
||||
Label5: TLabel;
|
||||
MemDataset1: TMemDataset;
|
||||
procedure DBGrid1SelectEditor(Sender: TObject; Column: TColumn;
|
||||
var Editor: TWinControl);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure OnCurrencyDBControlEnter(Sender: TObject);
|
||||
procedure OnDateDBControlEnter(Sender: TObject);
|
||||
procedure OnIntegerDBControlEnter(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.DBGrid1SelectEditor(Sender: TObject; Column: TColumn;
|
||||
var Editor: TWinControl);
|
||||
begin
|
||||
case Column.DesignIndex of
|
||||
0, 2: Editor := integerDbGridControl.Editor(Sender as TDBGrid);
|
||||
1: Editor := dateDbGridControl.Editor(Sender as TDBGrid);
|
||||
3: Editor := currencyDbGridControl.Editor(Sender as TDBGrid);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
// populate the memDataset
|
||||
for i := 1 to 10 do
|
||||
begin
|
||||
MemDataset1.Append;
|
||||
MemDataset1.FieldByName('ID').AsInteger := i;
|
||||
MemDataset1.FieldByName('DATE').AsDateTime := Now;
|
||||
MemDataset1.FieldByName('ID2').AsInteger := i * i;
|
||||
MemDataset1.FieldByName('TOTAL').AsFloat := i * i * i;
|
||||
MemDataset1.Post;
|
||||
end;
|
||||
MemDataset1.First;
|
||||
end;
|
||||
|
||||
procedure TForm1.OnCurrencyDBControlEnter(Sender: TObject);
|
||||
begin
|
||||
currencyDbControl.Enter(Sender as TDBEdit);
|
||||
end;
|
||||
|
||||
procedure TForm1.OnDateDBControlEnter(Sender: TObject);
|
||||
begin
|
||||
dateDbControl.Enter(Sender as TDBEdit);
|
||||
end;
|
||||
|
||||
procedure TForm1.OnIntegerDBControlEnter(Sender: TObject);
|
||||
begin
|
||||
integerDbControl.Enter(Sender as TDBEdit);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1,85 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<MainUnit Value="0"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<DestinationDirectory Value="$(TestDir)/testmemdataset/"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="3">
|
||||
<Item1>
|
||||
<PackageName Value="FCL"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="MemDSLaz"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item3>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="testmemdataset.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="testmemdataset"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="main"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="jcontrolutils.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="jcontrolutils"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="10"/>
|
||||
<Target>
|
||||
<Filename Value="testmemdataset"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<UseMsgFile Value="True"/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
@ -1,23 +0,0 @@
|
||||
program testmemdataset;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
clocale,
|
||||
{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, main, memdslaz
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
@ -1,155 +0,0 @@
|
||||
{ jcontrolutils
|
||||
|
||||
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 jcontrolutils;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Dialogs;
|
||||
|
||||
function CountChar(const s: string; ch: char): integer;
|
||||
procedure Split(const Delimiter: char; Input: string; Strings: TStrings);
|
||||
function NormalizeDate(const Value: string; theValue: TDateTime;
|
||||
const theFormat: string = ''): string;
|
||||
function NormalizeDateSeparator(const s: string): string;
|
||||
function IsValidDateString(const Value: string): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function CountChar(const s: string; ch: char): integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
for i := 1 to length(s) do
|
||||
if s[i] = ch then
|
||||
Inc(Result);
|
||||
end;
|
||||
|
||||
procedure Split(const Delimiter: char; Input: string; Strings: TStrings);
|
||||
begin
|
||||
Assert(Assigned(Strings));
|
||||
Strings.Clear;
|
||||
Strings.Delimiter := Delimiter;
|
||||
Strings.DelimitedText := Input;
|
||||
end;
|
||||
|
||||
function NormalizeDate(const Value: string; theValue: TDateTime;
|
||||
const theFormat: string): string;
|
||||
var
|
||||
texto: string;
|
||||
i: integer;
|
||||
d, m, y: word;
|
||||
ds, ms, ys: string;
|
||||
aDate: TDateTime;
|
||||
tokens: TStringList;
|
||||
aDateFormat: string;
|
||||
aChar: char;
|
||||
|
||||
procedure LittleEndianForm;
|
||||
begin
|
||||
// Note: only numeric input allowed (months names not implemented)
|
||||
if tokens[0] <> '' then
|
||||
ds := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ms := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ys := tokens[2];
|
||||
texto := ds + DateSeparator + ms + DateSeparator + ys;
|
||||
end;
|
||||
|
||||
procedure MiddleEndianForm;
|
||||
begin
|
||||
if tokens[0] <> '' then
|
||||
ms := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ds := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ys := tokens[2];
|
||||
texto := ms + DateSeparator + ds + DateSeparator + ys;
|
||||
end;
|
||||
|
||||
procedure BigEndianForm;
|
||||
begin
|
||||
if tokens[0] <> '' then
|
||||
ys := tokens[0];
|
||||
if (tokens.Count > 1) and (tokens[1] <> '') then
|
||||
ms := tokens[1];
|
||||
if (tokens.Count > 2) and (tokens[2] <> '') then
|
||||
ds := tokens[2];
|
||||
texto := ys + DateSeparator + ms + DateSeparator + ds;
|
||||
end;
|
||||
|
||||
begin
|
||||
if theFormat = '' then
|
||||
aDateFormat := ShortDateFormat
|
||||
else
|
||||
aDateFormat := theFormat;
|
||||
if theValue = 0 then
|
||||
DecodeDate(Now, y, m, d)
|
||||
else
|
||||
decodedate(theValue, y, m, d);
|
||||
ds := IntToStr(d);
|
||||
ms := IntToStr(m);
|
||||
ys := IntToStr(y);
|
||||
texto := Value;
|
||||
texto := NormalizeDateSeparator(texto);
|
||||
Result := texto; // default value
|
||||
i := countchar(texto, DateSeparator);
|
||||
tokens := TStringList.Create;
|
||||
Split(DateSeparator, texto, tokens);
|
||||
if tokens.Count > 0 then
|
||||
begin
|
||||
aChar := aDateFormat[1];
|
||||
case aChar of
|
||||
'd', 'D': LittleEndianForm;
|
||||
'm', 'M': MiddleEndianForm;
|
||||
'y', 'Y': BigEndianForm;
|
||||
end;
|
||||
|
||||
if IsValidDateString(texto) then
|
||||
begin
|
||||
aDate := StrToDate(texto);
|
||||
Result := FormatDateTime(aDateFormat, aDate);
|
||||
end;
|
||||
end;
|
||||
tokens.Free;
|
||||
end;
|
||||
|
||||
function NormalizeDateSeparator(const s: string): string;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
Result := s;
|
||||
for i := 1 to length(Result) do
|
||||
if Result[i] in ['.', ',', '/', '-'] then // valid date separators
|
||||
Result[i] := DateSeparator;
|
||||
end;
|
||||
|
||||
function IsValidDateString(const Value: string): boolean;
|
||||
begin
|
||||
if StrToDateDef(Value, MaxDateTime) = MaxDateTime then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1,358 +0,0 @@
|
||||
{ jinpututils
|
||||
|
||||
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 jinpututils;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, StdCtrls, SysUtils, jcontrolutils;
|
||||
type
|
||||
|
||||
{ TJCurrencyCtrl }
|
||||
|
||||
TJCurrencyCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TCustomEdit;
|
||||
theValue: Currency;
|
||||
fFormat : String;
|
||||
fDecimales : Integer;
|
||||
function getDecimales: integer;
|
||||
function getFormat: string;
|
||||
function getValue: Currency;
|
||||
procedure myEditEnter(Sender: TObject);
|
||||
procedure myEditExit(Sender: TObject);
|
||||
procedure formatInput;
|
||||
procedure setDecimales(const AValue: integer);
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure OnKeyPress(Sender: TObject; var key : char);
|
||||
function redondear(const AValue: Currency; const NDecimales: Integer) : Currency;
|
||||
function IsValidFloat(const Value: string): Boolean;
|
||||
procedure setValue(const AValue: Currency);
|
||||
public
|
||||
property format : String read getFormat write setFormat;
|
||||
property decimales : Integer read getDecimales write setDecimales;
|
||||
property value : Currency read getValue write setValue;
|
||||
constructor Create(widget : TCustomEdit);
|
||||
constructor Create(widget : TCustomEdit ;aDecimals : Integer; aFormat : String);
|
||||
end;
|
||||
|
||||
{ TJIntegerCtrl }
|
||||
|
||||
TJIntegerCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TCustomEdit;
|
||||
theValue: Integer;
|
||||
fFormat : String;
|
||||
function getFormat: string;
|
||||
function getValue: Integer;
|
||||
procedure myEditEnter(Sender: TObject);
|
||||
procedure myEditExit(Sender: TObject);
|
||||
procedure formatInput;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure OnKeyPress(Sender: TObject; var key : char);
|
||||
function IsValidInteger(const Value: string): Boolean;
|
||||
procedure setValue(const AValue: Integer);
|
||||
public
|
||||
property format : String read getFormat write setFormat;
|
||||
property value : Integer read getValue write setValue;
|
||||
constructor Create(widget : TCustomEdit);
|
||||
end;
|
||||
|
||||
{ TJDateCtrl }
|
||||
|
||||
TJDateCtrl = class(TObject)
|
||||
private
|
||||
myEdit: TCustomEdit;
|
||||
theValue: TDateTime;
|
||||
fFormat : String;
|
||||
function getFormat: string;
|
||||
function getValue: TDateTime;
|
||||
procedure myEditEnter(Sender: TObject);
|
||||
procedure myEditExit(Sender: TObject);
|
||||
procedure formatInput;
|
||||
procedure setFormat(const AValue: string);
|
||||
procedure OnKeyPress(Sender: TObject; var key : char);
|
||||
procedure setValue(const AValue: TDateTime);
|
||||
public
|
||||
function isNull : Boolean;
|
||||
property format : String read getFormat write setFormat;
|
||||
property value : TDateTime read getValue write setValue;
|
||||
constructor Create(widget : TCustomEdit);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
math,dateutils,Graphics,Dialogs;
|
||||
|
||||
|
||||
{ TJCurrencyCtrl }
|
||||
|
||||
function TJCurrencyCtrl.getDecimales: integer;
|
||||
begin
|
||||
result:= fDecimales;
|
||||
end;
|
||||
|
||||
function TJCurrencyCtrl.getFormat: string;
|
||||
begin
|
||||
result := fFormat;
|
||||
end;
|
||||
|
||||
function TJCurrencyCtrl.getValue: Currency;
|
||||
begin
|
||||
result := theValue;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.myEditEnter(Sender: TObject);
|
||||
begin
|
||||
myEdit.Caption:= FloatToStr(theValue);
|
||||
myEdit.SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.myEditExit(Sender: TObject);
|
||||
begin
|
||||
if IsValidFloat(myEdit.Caption) then
|
||||
theValue:= StrToCurr(myEdit.Caption)
|
||||
else
|
||||
begin
|
||||
ShowMessage(myEdit.Caption + ' no es un valor válido');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
theValue:= redondear(theValue, fDecimales);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.formatInput;
|
||||
begin
|
||||
myEdit.Caption:= FormatFloat(format, theValue);
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.setDecimales(const AValue: integer);
|
||||
begin
|
||||
// Poner decimales, redondear valor y mostrarlo
|
||||
if AValue >= 0 then
|
||||
fDecimales:= AValue;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat:= AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if (Key in ['.',',']) then Key := Decimalseparator;
|
||||
if (key = DecimalSeparator) and (Pos(key, myEdit.Caption) >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;
|
||||
end;
|
||||
|
||||
function TJCurrencyCtrl.redondear(const AValue: Currency;
|
||||
const NDecimales: Integer): Currency;
|
||||
begin
|
||||
redondear := round(AValue * power(10, NDecimales)) / power(10, NDecimales);
|
||||
end;
|
||||
|
||||
function TJCurrencyCtrl.IsValidFloat(const Value: string): Boolean;
|
||||
begin
|
||||
if StrToCurrDef(value, MaxCurrency) = MaxCurrency then Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJCurrencyCtrl.setValue(const AValue: Currency);
|
||||
begin
|
||||
theValue:= redondear(AValue, fDecimales);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
constructor TJCurrencyCtrl.Create(widget: TCustomEdit);
|
||||
begin
|
||||
myEdit:= widget;
|
||||
myEdit.OnEnter:= @myEditEnter;
|
||||
myEdit.OnExit:= @myEditExit;
|
||||
myEdit.OnKeyPress:= @OnKeyPress;
|
||||
myEdit.caption:= ''; // avoid prev input
|
||||
format:= '#,0.00 €';
|
||||
fDecimales:= 2;
|
||||
end;
|
||||
constructor TJCurrencyCtrl.Create(widget: TCustomEdit; aDecimals: Integer;
|
||||
aFormat: String);
|
||||
begin
|
||||
myEdit:= widget;
|
||||
myEdit.OnEnter:= @myEditEnter;
|
||||
myEdit.OnExit:= @myEditExit;
|
||||
myEdit.OnKeyPress:= @OnKeyPress;
|
||||
myEdit.caption:= ''; // avoid prev input
|
||||
format:= aFormat;
|
||||
fDecimales:= aDecimals;
|
||||
end;
|
||||
|
||||
|
||||
{ TJIntegerCtrl }
|
||||
|
||||
function TJIntegerCtrl.getFormat: string;
|
||||
begin
|
||||
Result := fFormat;
|
||||
end;
|
||||
|
||||
function TJIntegerCtrl.getValue: Integer;
|
||||
begin
|
||||
Result := theValue;
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.myEditEnter(Sender: TObject);
|
||||
begin
|
||||
myEdit.Caption:= IntToStr(theValue);
|
||||
myEdit.SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.myEditExit(Sender: TObject);
|
||||
begin
|
||||
if IsValidInteger(myEdit.Caption) then
|
||||
theValue:= StrToInt(myEdit.Caption)
|
||||
else
|
||||
begin
|
||||
ShowMessage(myEdit.Caption + ' no es un valor válido');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.formatInput;
|
||||
begin
|
||||
myEdit.Caption:= FormatFloat(format, theValue);
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat:= AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9',#8,#9,'-']) then Key := #0;
|
||||
end;
|
||||
|
||||
function TJIntegerCtrl.IsValidInteger(const Value: string): Boolean;
|
||||
begin
|
||||
if StrToIntDef(value, MaxInt) = MaxInt then
|
||||
Result := False
|
||||
else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TJIntegerCtrl.setValue(const AValue: Integer);
|
||||
begin
|
||||
theValue:= AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
constructor TJIntegerCtrl.Create(widget: TCustomEdit);
|
||||
begin
|
||||
myEdit:= widget;
|
||||
myEdit.OnEnter:= @myEditEnter;
|
||||
myEdit.OnExit:= @myEditExit;
|
||||
myEdit.OnKeyPress:= @OnKeyPress;
|
||||
myEdit.caption:= ''; // avoid prev input
|
||||
format:= '0';
|
||||
end;
|
||||
|
||||
{ TJDateCtrl }
|
||||
|
||||
function TJDateCtrl.getFormat: string;
|
||||
begin
|
||||
result := fFormat;
|
||||
end;
|
||||
|
||||
function TJDateCtrl.getValue: TDateTime;
|
||||
begin
|
||||
Result := theValue;
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.myEditEnter(Sender: TObject);
|
||||
begin
|
||||
if theValue <> 0 then
|
||||
myEdit.Caption:= FormatDateTime(format, theValue)
|
||||
else
|
||||
myEdit.Caption := '';
|
||||
myEdit.SelectAll;
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.myEditExit(Sender: TObject);
|
||||
begin
|
||||
myEdit.Caption:= NormalizeDate(myEdit.Caption, theValue);
|
||||
if Length(myEdit.Caption) = 0 then
|
||||
theValue := 0
|
||||
else
|
||||
if IsValidDateString(myEdit.Caption) then
|
||||
theValue:= StrToDate(myEdit.Caption)
|
||||
else
|
||||
begin
|
||||
ShowMessage(myEdit.Caption + ' no es una fecha válida');
|
||||
myEdit.SetFocus;
|
||||
end;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.formatInput;
|
||||
begin
|
||||
if theValue <> 0 then
|
||||
myEdit.Caption:= FormatDateTime(format, theValue);
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.setFormat(const AValue: string);
|
||||
begin
|
||||
fFormat:= AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||
begin
|
||||
if not (Key in ['0'..'9',#8,#9, '.', '-', '/']) then Key := #0;
|
||||
end;
|
||||
|
||||
procedure TJDateCtrl.setValue(const AValue: TDateTime);
|
||||
begin
|
||||
theValue:= AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
function TJDateCtrl.isNull: Boolean;
|
||||
begin
|
||||
Result := theValue = 0;
|
||||
end;
|
||||
|
||||
constructor TJDateCtrl.Create(widget: TCustomEdit);
|
||||
begin
|
||||
myEdit:= widget;
|
||||
myEdit.OnEnter:= @myEditEnter;
|
||||
myEdit.OnExit:= @myEditExit;
|
||||
myEdit.OnKeyPress:= @OnKeyPress;
|
||||
myEdit.caption:= ''; // avoid prev input
|
||||
theValue:= now;
|
||||
format:= 'dd/mm/yyyy';
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -1,128 +0,0 @@
|
||||
object Form1: TForm1
|
||||
Left = 334
|
||||
Height = 300
|
||||
Top = 239
|
||||
Width = 400
|
||||
ActiveControl = Edit2
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 300
|
||||
ClientWidth = 400
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
LCLVersion = '0.9.31'
|
||||
object Label1: TLabel
|
||||
Left = 8
|
||||
Height = 18
|
||||
Top = 40
|
||||
Width = 92
|
||||
Caption = 'Currency Input'
|
||||
ParentColor = False
|
||||
end
|
||||
object Edit2: TEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 37
|
||||
Width = 104
|
||||
Alignment = taRightJustify
|
||||
TabOrder = 0
|
||||
Text = 'Edit2'
|
||||
end
|
||||
object Edit3: TEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 64
|
||||
Width = 104
|
||||
Alignment = taRightJustify
|
||||
TabOrder = 1
|
||||
Text = 'Edit3'
|
||||
end
|
||||
object Edit4: TEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 91
|
||||
Width = 104
|
||||
Alignment = taRightJustify
|
||||
TabOrder = 2
|
||||
Text = 'Edit4'
|
||||
end
|
||||
object BitBtn1: TBitBtn
|
||||
Left = 304
|
||||
Height = 34
|
||||
Top = 256
|
||||
Width = 88
|
||||
Caption = '&Close'
|
||||
Kind = bkClose
|
||||
OnClick = BitBtn1Click
|
||||
TabOrder = 4
|
||||
end
|
||||
object LabeledEdit1: TLabeledEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 118
|
||||
Width = 104
|
||||
Alignment = taRightJustify
|
||||
EditLabel.AnchorSideLeft.Control = LabeledEdit1
|
||||
EditLabel.AnchorSideTop.Control = LabeledEdit1
|
||||
EditLabel.AnchorSideTop.Side = asrCenter
|
||||
EditLabel.AnchorSideRight.Control = LabeledEdit1
|
||||
EditLabel.AnchorSideBottom.Control = LabeledEdit1
|
||||
EditLabel.Left = 9
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 122
|
||||
EditLabel.Width = 124
|
||||
EditLabel.Caption = 'TLabeledEdit control'
|
||||
EditLabel.ParentColor = False
|
||||
LabelPosition = lpLeft
|
||||
TabOrder = 3
|
||||
Text = '123'
|
||||
end
|
||||
object LabeledEdit2: TLabeledEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 144
|
||||
Width = 104
|
||||
Alignment = taRightJustify
|
||||
EditLabel.AnchorSideLeft.Control = LabeledEdit2
|
||||
EditLabel.AnchorSideTop.Control = LabeledEdit2
|
||||
EditLabel.AnchorSideTop.Side = asrCenter
|
||||
EditLabel.AnchorSideRight.Control = LabeledEdit2
|
||||
EditLabel.AnchorSideBottom.Control = LabeledEdit2
|
||||
EditLabel.Left = 37
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 148
|
||||
EditLabel.Width = 96
|
||||
EditLabel.Caption = 'Integer number'
|
||||
EditLabel.ParentColor = False
|
||||
LabelPosition = lpLeft
|
||||
TabOrder = 5
|
||||
end
|
||||
object LabeledEdit3: TLabeledEdit
|
||||
Left = 136
|
||||
Height = 27
|
||||
Top = 176
|
||||
Width = 104
|
||||
EditLabel.AnchorSideLeft.Control = LabeledEdit3
|
||||
EditLabel.AnchorSideTop.Control = LabeledEdit3
|
||||
EditLabel.AnchorSideTop.Side = asrCenter
|
||||
EditLabel.AnchorSideRight.Control = LabeledEdit3
|
||||
EditLabel.AnchorSideBottom.Control = LabeledEdit3
|
||||
EditLabel.Left = 69
|
||||
EditLabel.Height = 18
|
||||
EditLabel.Top = 180
|
||||
EditLabel.Width = 64
|
||||
EditLabel.Caption = 'Date input'
|
||||
EditLabel.ParentColor = False
|
||||
LabelPosition = lpLeft
|
||||
TabOrder = 6
|
||||
end
|
||||
object Button1: TButton
|
||||
Left = 248
|
||||
Height = 27
|
||||
Top = 176
|
||||
Width = 44
|
||||
AutoSize = True
|
||||
Caption = 'Date?'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 7
|
||||
end
|
||||
end
|
@ -1,42 +0,0 @@
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'N'#1#6'Height'#3','#1#3'Top'#3#239#0#5'Wi'
|
||||
+'dth'#3#144#1#13'ActiveControl'#7#5'Edit2'#7'Caption'#6#5'Form1'#12'ClientHe'
|
||||
+'ight'#3','#1#11'ClientWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'#9'OnDestr'
|
||||
+'oy'#7#11'FormDestroy'#10'LCLVersion'#6#6'0.9.31'#0#6'TLabel'#6'Label1'#4'Le'
|
||||
+'ft'#2#8#6'Height'#2#18#3'Top'#2'('#5'Width'#2'\'#7'Caption'#6#14'Currency I'
|
||||
+'nput'#11'ParentColor'#8#0#0#5'TEdit'#5'Edit2'#4'Left'#3#136#0#6'Height'#2#27
|
||||
+#3'Top'#2'%'#5'Width'#2'h'#9'Alignment'#7#14'taRightJustify'#8'TabOrder'#2#0
|
||||
+#4'Text'#6#5'Edit2'#0#0#5'TEdit'#5'Edit3'#4'Left'#3#136#0#6'Height'#2#27#3'T'
|
||||
+'op'#2'@'#5'Width'#2'h'#9'Alignment'#7#14'taRightJustify'#8'TabOrder'#2#1#4
|
||||
+'Text'#6#5'Edit3'#0#0#5'TEdit'#5'Edit4'#4'Left'#3#136#0#6'Height'#2#27#3'Top'
|
||||
+#2'['#5'Width'#2'h'#9'Alignment'#7#14'taRightJustify'#8'TabOrder'#2#2#4'Text'
|
||||
+#6#5'Edit4'#0#0#7'TBitBtn'#7'BitBtn1'#4'Left'#3'0'#1#6'Height'#2'"'#3'Top'#3
|
||||
+#0#1#5'Width'#2'X'#7'Caption'#6#6'&Close'#4'Kind'#7#7'bkClose'#7'OnClick'#7
|
||||
+#12'BitBtn1Click'#8'TabOrder'#2#4#0#0#12'TLabeledEdit'#12'LabeledEdit1'#4'Le'
|
||||
+'ft'#3#136#0#6'Height'#2#27#3'Top'#2'v'#5'Width'#2'h'#9'Alignment'#7#14'taRi'
|
||||
+'ghtJustify EditLabel.AnchorSideLeft.Control'#7#12'LabeledEdit1'#31'EditLabe'
|
||||
+'l.AnchorSideTop.Control'#7#12'LabeledEdit1'#28'EditLabel.AnchorSideTop.Side'
|
||||
+#7#9'asrCenter!EditLabel.AnchorSideRight.Control'#7#12'LabeledEdit1"EditLabe'
|
||||
+'l.AnchorSideBottom.Control'#7#12'LabeledEdit1'#14'EditLabel.Left'#2#9#16'Ed'
|
||||
+'itLabel.Height'#2#18#13'EditLabel.Top'#2'z'#15'EditLabel.Width'#2'|'#17'Edi'
|
||||
+'tLabel.Caption'#6#20'TLabeledEdit control'#21'EditLabel.ParentColor'#8#13'L'
|
||||
+'abelPosition'#7#6'lpLeft'#8'TabOrder'#2#3#4'Text'#6#3'123'#0#0#12'TLabeledE'
|
||||
+'dit'#12'LabeledEdit2'#4'Left'#3#136#0#6'Height'#2#27#3'Top'#3#144#0#5'Width'
|
||||
+#2'h'#9'Alignment'#7#14'taRightJustify EditLabel.AnchorSideLeft.Control'#7#12
|
||||
+'LabeledEdit2'#31'EditLabel.AnchorSideTop.Control'#7#12'LabeledEdit2'#28'Edi'
|
||||
+'tLabel.AnchorSideTop.Side'#7#9'asrCenter!EditLabel.AnchorSideRight.Control'
|
||||
+#7#12'LabeledEdit2"EditLabel.AnchorSideBottom.Control'#7#12'LabeledEdit2'#14
|
||||
+'EditLabel.Left'#2'%'#16'EditLabel.Height'#2#18#13'EditLabel.Top'#3#148#0#15
|
||||
+'EditLabel.Width'#2'`'#17'EditLabel.Caption'#6#14'Integer number'#21'EditLab'
|
||||
+'el.ParentColor'#8#13'LabelPosition'#7#6'lpLeft'#8'TabOrder'#2#5#0#0#12'TLab'
|
||||
+'eledEdit'#12'LabeledEdit3'#4'Left'#3#136#0#6'Height'#2#27#3'Top'#3#176#0#5
|
||||
+'Width'#2'h EditLabel.AnchorSideLeft.Control'#7#12'LabeledEdit3'#31'EditLabe'
|
||||
+'l.AnchorSideTop.Control'#7#12'LabeledEdit3'#28'EditLabel.AnchorSideTop.Side'
|
||||
+#7#9'asrCenter!EditLabel.AnchorSideRight.Control'#7#12'LabeledEdit3"EditLabe'
|
||||
+'l.AnchorSideBottom.Control'#7#12'LabeledEdit3'#14'EditLabel.Left'#2'E'#16'E'
|
||||
+'ditLabel.Height'#2#18#13'EditLabel.Top'#3#180#0#15'EditLabel.Width'#2'@'#17
|
||||
+'EditLabel.Caption'#6#10'Date input'#21'EditLabel.ParentColor'#8#13'LabelPos'
|
||||
+'ition'#7#6'lpLeft'#8'TabOrder'#2#6#0#0#7'TButton'#7'Button1'#4'Left'#3#248#0
|
||||
+#6'Height'#2#27#3'Top'#3#176#0#5'Width'#2','#8'AutoSize'#9#7'Caption'#6#5'Da'
|
||||
+'te?'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2#7#0#0#0
|
||||
]);
|
@ -1,86 +0,0 @@
|
||||
unit main;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, jinpututils, Buttons, ExtCtrls, Spin, LCLType, EditBtn;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
BitBtn1: TBitBtn;
|
||||
Button1: TButton;
|
||||
Edit2: TEdit;
|
||||
Edit3: TEdit;
|
||||
Edit4: TEdit;
|
||||
Label1: TLabel;
|
||||
LabeledEdit1: TLabeledEdit;
|
||||
LabeledEdit2: TLabeledEdit;
|
||||
LabeledEdit3: TLabeledEdit;
|
||||
procedure BitBtn1Click(Sender: TObject);
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
campoImporte : TJCurrencyCtrl;
|
||||
campoLitros : TJCurrencyCtrl;
|
||||
campoGrados : TJCurrencyCtrl;
|
||||
campoEntero : TJIntegerCtrl;
|
||||
campoFecha : TJDateCtrl;
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
campoImporte:= TJCurrencyCtrl.Create(Edit2);
|
||||
campoLitros:= TJCurrencyCtrl.Create(Edit3, 2, '#,0.0000 L');
|
||||
campoGrados:= TJCurrencyCtrl.Create(LabeledEdit1);
|
||||
campoGrados.format:= '#,0.00 º';
|
||||
campoEntero:= TJIntegerCtrl.Create(LabeledEdit2);
|
||||
campoEntero.format := ',0 º';
|
||||
campoFecha := TJDateCtrl.Create(LabeledEdit3);
|
||||
end;
|
||||
|
||||
procedure TForm1.BitBtn1Click(Sender: TObject);
|
||||
begin
|
||||
Application.Terminate;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
begin
|
||||
if campoFecha.isNull then
|
||||
ShowMessage('No Date')
|
||||
else
|
||||
ShowMessage('has Date');
|
||||
end;
|
||||
|
||||
|
||||
procedure TForm1.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
campoImporte.Free;
|
||||
campoLitros.Free;
|
||||
campoGrados.Free;
|
||||
campoEntero.Free;
|
||||
campoFecha.Free;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I main.lrs}
|
||||
|
||||
end.
|
||||
|
@ -1,81 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<MainUnit Value="0"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<Language Value=""/>
|
||||
<CharSet Value=""/>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<DestinationDirectory Value="$(TestDir)/testnodbinput/"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="testnuminput.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="testnuminput"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="main"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="jinpututils.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="jinpututils"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="jcontrolutils.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="jcontrolutils"/>
|
||||
</Unit3>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="10"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
@ -1,23 +0,0 @@
|
||||
program testnuminput;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
clocale,
|
||||
{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms
|
||||
{ you can add units after this }, main, jcontrolutils, LResources;
|
||||
|
||||
{$IFDEF WINDOWS}{$R testnuminput.rc}{$ENDIF}
|
||||
|
||||
begin
|
||||
{$I testnuminput.lrs}
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user