diff --git a/components/jujiboutils/examples/testmemdataset/jcontrolutils.pas b/components/jujiboutils/examples/testmemdataset/jcontrolutils.pas new file mode 100644 index 000000000..c1cf74568 --- /dev/null +++ b/components/jujiboutils/examples/testmemdataset/jcontrolutils.pas @@ -0,0 +1,82 @@ +unit jcontrolutils; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +function ReplaceChar(const s: string; ch1: char; ch2: char): string; +function CountChar(const s: string; ch: char): integer; +procedure Split(const Delimiter: char; Input: string; Strings: TStrings); +function NormalizeDate(const Value: string; theValue: TDateTime): string; +function NormalizeDateSeparator(const s: string): string; + +implementation + +function ReplaceChar(const s: string; ch1: char; ch2: char): string; +var + i: integer; +begin + Result := s; + for i := 1 to length(Result) do + if Result[i] = ch1 then + Result[i] := ch2; +end; + +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): string; +var + texto: string; + i: integer; + d, m, y: word; +begin + if theValue = 0 then + DecodeDate(Now, y, m, d) + else + decodedate(theValue, y, m, d); + // normalize date + texto := Value; + texto:= NormalizeDateSeparator(texto); + //texto := replacechar(texto, '.', DateSeparator); + //texto := replacechar(texto, '-', DateSeparator); + //texto := replacechar(texto, '/', DateSeparator); + i := countchar(texto, DateSeparator); + + case i of + 1: texto := texto + DateSeparator + IntToStr(y); + 0: texto := texto + DateSeparator + IntToStr(m) + DateSeparator + IntToStr(y); + end; + Result := texto; +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; + +end. + diff --git a/components/jujiboutils/examples/testmemdataset/jdbgridutils.pas b/components/jujiboutils/examples/testmemdataset/jdbgridutils.pas index fcafc457f..97b0b4ce3 100644 --- a/components/jujiboutils/examples/testmemdataset/jdbgridutils.pas +++ b/components/jujiboutils/examples/testmemdataset/jdbgridutils.pas @@ -22,7 +22,8 @@ unit jdbgridutils; interface uses - Classes, SysUtils, Grids, Dialogs, StdCtrls, LCLType, DBGrids, Controls, DB; + Classes, SysUtils, Grids, Dialogs, LCLType, DBGrids, Controls, DB, + jcontrolutils; type @@ -102,10 +103,6 @@ var integerDbGridControl: TJDbGridIntegerCtrl; currencyDbGridControl: TJDbGridCurrencyCtrl; -function replacechar(const s: string; ch1: char; ch2: char): string; -function countchar(const s: string; ch: char): integer; -procedure Split(const Delimiter: char; Input: string; Strings: TStrings); - implementation uses @@ -503,34 +500,6 @@ begin Result := CellEditor; end; -function replacechar(const s: string; ch1: char; ch2: char): string; -var - i: integer; -begin - Result := s; - for i := 1 to length(Result) do - if Result[i] = ch1 then - Result[i] := ch2; -end; - -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; - procedure CreateResources; begin dateDbGridControl := TJDbGridDateCtrl.Create; diff --git a/components/jujiboutils/examples/testmemdataset/jdbutils.pas b/components/jujiboutils/examples/testmemdataset/jdbutils.pas index 6f33342a6..324562790 100644 --- a/components/jujiboutils/examples/testmemdataset/jdbutils.pas +++ b/components/jujiboutils/examples/testmemdataset/jdbutils.pas @@ -22,7 +22,7 @@ unit jdbutils; interface uses - Classes, StdCtrls, SysUtils, DBCtrls; + Classes, SysUtils, DBCtrls, jcontrolutils; type @@ -71,7 +71,6 @@ type procedure setFormat(const AValue: string); procedure OnKeyPress(Sender: TObject; var key: char); function IsValidDate(const Value: string): boolean; - function NormalizeDate(const Value: string): string; public function isNull: boolean; property format: string read getFormat write setFormat; @@ -83,9 +82,6 @@ var integerDbControl: TJDBIntegerCtrl; currencyDbControl: TJDBCurrencyCtrl; -function replacechar(const s: string; ch1: char; ch2: char): string; -function countchar(const s: string; ch: char): integer; -procedure Split(const Delimiter: char; Input: string; Strings: TStrings); implementation @@ -225,7 +221,7 @@ procedure TJDBDateCtrl.myEditOnEditingDone(Sender: TObject); var bufCaption: string; begin - bufCaption := NormalizeDate(myEdit.Caption); + bufCaption := NormalizeDate(myEdit.Caption, theValue); if Length(myEdit.Caption) = 0 then theValue := 0 else @@ -270,30 +266,6 @@ begin Result := True; end; -function TJDBDateCtrl.NormalizeDate(const Value: string): string; -var - texto: string; - i: integer; - d, m, y: word; -begin - if theValue = 0 then - DecodeDate(Now, y, m, d) - else - decodedate(theValue, y, m, d); - // normalize date - texto := Value; - texto := replacechar(texto, '.', DateSeparator); - texto := replacechar(texto, '-', DateSeparator); - texto := replacechar(texto, '/', DateSeparator); - i := countchar(texto, DateSeparator); - - case i of - 1: texto := texto + DateSeparator + IntToStr(y); - 0: texto := texto + DateSeparator + IntToStr(m) + DateSeparator + IntToStr(y); - end; - Result := texto; -end; - function TJDBDateCtrl.isNull: boolean; begin Result := theValue = 0; @@ -309,34 +281,6 @@ begin myEdit.SelectAll; end; -function replacechar(const s: string; ch1: char; ch2: char): string; -var - i: integer; -begin - Result := s; - for i := 1 to length(Result) do - if Result[i] = ch1 then - Result[i] := ch2; -end; - -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; - procedure CreateResources; begin dateDbControl := TJDBDateCtrl.Create; diff --git a/components/jujiboutils/examples/testmemdataset/testmemdataset.lpi b/components/jujiboutils/examples/testmemdataset/testmemdataset.lpi index 27bcb4770..3dac0882e 100644 --- a/components/jujiboutils/examples/testmemdataset/testmemdataset.lpi +++ b/components/jujiboutils/examples/testmemdataset/testmemdataset.lpi @@ -40,7 +40,7 @@ - + @@ -53,6 +53,11 @@ + + + + + @@ -72,6 +77,9 @@ + + +