You've already forked lazarus-ccr
Code refactoring
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1943 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -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.
|
||||||
|
|
@ -22,7 +22,8 @@ unit jdbgridutils;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Grids, Dialogs, StdCtrls, LCLType, DBGrids, Controls, DB;
|
Classes, SysUtils, Grids, Dialogs, LCLType, DBGrids, Controls, DB,
|
||||||
|
jcontrolutils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -102,10 +103,6 @@ var
|
|||||||
integerDbGridControl: TJDbGridIntegerCtrl;
|
integerDbGridControl: TJDbGridIntegerCtrl;
|
||||||
currencyDbGridControl: TJDbGridCurrencyCtrl;
|
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
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -503,34 +500,6 @@ begin
|
|||||||
Result := CellEditor;
|
Result := CellEditor;
|
||||||
end;
|
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;
|
procedure CreateResources;
|
||||||
begin
|
begin
|
||||||
dateDbGridControl := TJDbGridDateCtrl.Create;
|
dateDbGridControl := TJDbGridDateCtrl.Create;
|
||||||
|
@ -22,7 +22,7 @@ unit jdbutils;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, StdCtrls, SysUtils, DBCtrls;
|
Classes, SysUtils, DBCtrls, jcontrolutils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -71,7 +71,6 @@ type
|
|||||||
procedure setFormat(const AValue: string);
|
procedure setFormat(const AValue: string);
|
||||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||||
function IsValidDate(const Value: string): boolean;
|
function IsValidDate(const Value: string): boolean;
|
||||||
function NormalizeDate(const Value: string): string;
|
|
||||||
public
|
public
|
||||||
function isNull: boolean;
|
function isNull: boolean;
|
||||||
property format: string read getFormat write setFormat;
|
property format: string read getFormat write setFormat;
|
||||||
@ -83,9 +82,6 @@ var
|
|||||||
integerDbControl: TJDBIntegerCtrl;
|
integerDbControl: TJDBIntegerCtrl;
|
||||||
currencyDbControl: TJDBCurrencyCtrl;
|
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
|
implementation
|
||||||
|
|
||||||
@ -225,7 +221,7 @@ procedure TJDBDateCtrl.myEditOnEditingDone(Sender: TObject);
|
|||||||
var
|
var
|
||||||
bufCaption: string;
|
bufCaption: string;
|
||||||
begin
|
begin
|
||||||
bufCaption := NormalizeDate(myEdit.Caption);
|
bufCaption := NormalizeDate(myEdit.Caption, theValue);
|
||||||
if Length(myEdit.Caption) = 0 then
|
if Length(myEdit.Caption) = 0 then
|
||||||
theValue := 0
|
theValue := 0
|
||||||
else
|
else
|
||||||
@ -270,30 +266,6 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
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;
|
function TJDBDateCtrl.isNull: boolean;
|
||||||
begin
|
begin
|
||||||
Result := theValue = 0;
|
Result := theValue = 0;
|
||||||
@ -309,34 +281,6 @@ begin
|
|||||||
myEdit.SelectAll;
|
myEdit.SelectAll;
|
||||||
end;
|
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;
|
procedure CreateResources;
|
||||||
begin
|
begin
|
||||||
dateDbControl := TJDBDateCtrl.Create;
|
dateDbControl := TJDBDateCtrl.Create;
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<PackageName Value="LCL"/>
|
<PackageName Value="LCL"/>
|
||||||
</Item3>
|
</Item3>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="2">
|
<Units Count="3">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="testmemdataset.lpr"/>
|
<Filename Value="testmemdataset.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -53,6 +53,11 @@
|
|||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="main"/>
|
<UnitName Value="main"/>
|
||||||
</Unit1>
|
</Unit1>
|
||||||
|
<Unit2>
|
||||||
|
<Filename Value="jcontrolutils.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="jcontrolutils"/>
|
||||||
|
</Unit2>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
@ -72,6 +77,9 @@
|
|||||||
</Options>
|
</Options>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
Reference in New Issue
Block a user