New fcuntion in TRxCloseFormValidator, localization. New function CloneRecord in DBUtils

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2370 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2012-03-29 16:01:32 +00:00
parent 2e40e2dbee
commit 768e780780
6 changed files with 133 additions and 28 deletions

View File

@@ -120,6 +120,7 @@ procedure CheckRequiredField(Field: TField);
procedure CheckRequiredFields(const Fields: array of TField); procedure CheckRequiredFields(const Fields: array of TField);
function ExtractFieldName(const Fields: string; var Pos: Integer): string; function ExtractFieldName(const Fields: string; var Pos: Integer): string;
procedure FillValueForField(const Field: TField; Value:Variant); procedure FillValueForField(const Field: TField; Value:Variant);
procedure CloneRecord(DataSet: TDataSet; IgnoreFields: array of const);
{ SQL expressions } { SQL expressions }
@@ -937,4 +938,60 @@ begin
end; end;
end; end;
function FieldInArray(Field: TField; Arr: array of const): boolean;
var
i: integer;
CI: boolean;
begin
Result := False;
for i := Low(Arr) to High(Arr) do
begin
with Arr[i] do
begin
case VType of
vtInteger: Result := Field.Index = VInteger;
vtPChar:
Result :=
AnsiUpperCase(Field.FieldName) = AnsiUpperCase(vPChar);
vtString,
vtAnsiString:
Result :=UpperCase(Field.FieldName) = UpperCase(string(VAnsiString));
end
end;
if Result then
exit;
end;
end;
procedure CloneRecord(DataSet: TDataSet; IgnoreFields: array of const);
var
Rec:Array of variant;
i:integer;
begin
if not DataSet.Active then exit;
i:=DataSet.FieldCount;
SetLength(Rec, DataSet.FieldCount);
for i:=0 to DataSet.FieldCount-1 do
begin
if (DataSet.Fields[i].FieldKind in [fkData]) and (not DataSet.Fields[i].IsBlob)
and (not FieldInArray(DataSet.Fields[i], IgnoreFields)) then
begin
Rec[i] := DataSet.Fields[i].Value;
end;
end;
DataSet.Append;
for i:=0 to DataSet.FieldCount-1 do
begin
if (DataSet.Fields[i].FieldKind in [fkData]) and (not DataSet.Fields[i].IsBlob)
and (not FieldInArray(DataSet.Fields[i], IgnoreFields)) then
begin
DataSet.Fields[i].Value:=Rec[i];
Rec[i]:=Null;
end;
end;
end;
end. end.

View File

@@ -41,6 +41,10 @@ msgstr "Derecho"
msgid "Carbon widget set" msgid "Carbon widget set"
msgstr "" msgstr ""
#: rxconst.sclosevaliderror
msgid "Error. Expected vailes..."
msgstr ""
#: rxconst.sdatedlgtitle #: rxconst.sdatedlgtitle
msgid "Select a Date" msgid "Select a Date"
msgstr "Seleccionar Fecha" msgstr "Seleccionar Fecha"
@@ -65,6 +69,10 @@ msgstr "Destino"
msgid "Source" msgid "Source"
msgstr "Fuente" msgstr "Fuente"
#: rxconst.sexptcontrolnotfound
msgid "Control not found in validate %s."
msgstr ""
#: rxconst.sfilenotexec #: rxconst.sfilenotexec
msgid "File specified is not an executable file, dynamic-link library, or icon file" msgid "File specified is not an executable file, dynamic-link library, or icon file"
msgstr "Fichero especificado no es un fichero ejecutable, vinculo dinamico, o fichero de icono" msgstr "Fichero especificado no es un fichero ejecutable, vinculo dinamico, o fichero de icono"
@@ -141,6 +149,10 @@ msgstr "Anterior A?o|"
msgid "QT widget set" msgid "QT widget set"
msgstr "" msgstr ""
#: rxconst.sreqvalue
msgid "Error. Expected value for filed %s."
msgstr ""
#: rxconst.sshowcaption #: rxconst.sshowcaption
msgid "Show caption" msgid "Show caption"
msgstr "Mostrar titulo" msgstr "Mostrar titulo"

View File

@@ -41,6 +41,10 @@ msgstr ""
msgid "Carbon widget set" msgid "Carbon widget set"
msgstr "" msgstr ""
#: rxconst.sclosevaliderror
msgid "Error. Expected vailes..."
msgstr ""
#: rxconst.sdatedlgtitle #: rxconst.sdatedlgtitle
msgid "Select a Date" msgid "Select a Date"
msgstr "" msgstr ""
@@ -65,6 +69,10 @@ msgstr ""
msgid "Source" msgid "Source"
msgstr "" msgstr ""
#: rxconst.sexptcontrolnotfound
msgid "Control not found in validate %s."
msgstr ""
#: rxconst.sfilenotexec #: rxconst.sfilenotexec
msgid "File specified is not an executable file, dynamic-link library, or icon file" msgid "File specified is not an executable file, dynamic-link library, or icon file"
msgstr "" msgstr ""
@@ -141,6 +149,10 @@ msgstr ""
msgid "QT widget set" msgid "QT widget set"
msgstr "" msgstr ""
#: rxconst.sreqvalue
msgid "Error. Expected value for filed %s."
msgstr ""
#: rxconst.sshowcaption #: rxconst.sshowcaption
msgid "Show caption" msgid "Show caption"
msgstr "" msgstr ""

View File

@@ -41,6 +41,10 @@ msgstr "Вправо"
msgid "Carbon widget set" msgid "Carbon widget set"
msgstr "Графический интерфейс Carbon" msgstr "Графический интерфейс Carbon"
#: rxconst.sclosevaliderror
msgid "Error. Expected vailes..."
msgstr "Ошибка. Ожидается значение..."
#: rxconst.sdatedlgtitle #: rxconst.sdatedlgtitle
msgid "Select a Date" msgid "Select a Date"
msgstr "Выберите дату" msgstr "Выберите дату"
@@ -65,6 +69,10 @@ msgstr "Выбор"
msgid "Source" msgid "Source"
msgstr "Источник" msgstr "Источник"
#: rxconst.sexptcontrolnotfound
msgid "Control not found in validate %s."
msgstr "Элемент управления не найден в валидаторе %s"
#: rxconst.sfilenotexec #: rxconst.sfilenotexec
msgid "File specified is not an executable file, dynamic-link library, or icon file" msgid "File specified is not an executable file, dynamic-link library, or icon file"
msgstr "Указанный файл не исполняемый, не библиотека и не иконка" msgstr "Указанный файл не исполняемый, не библиотека и не иконка"
@@ -141,6 +149,10 @@ msgstr "Превыдущий год|"
msgid "QT widget set" msgid "QT widget set"
msgstr "Графический интерфейс QT" msgstr "Графический интерфейс QT"
#: rxconst.sreqvalue
msgid "Error. Expected value for filed %s."
msgstr "Поле %s. Требуется значение"
#: rxconst.sshowcaption #: rxconst.sshowcaption
msgid "Show caption" msgid "Show caption"
msgstr "Отображать заголовок" msgstr "Отображать заголовок"

View File

@@ -38,11 +38,6 @@ interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB; Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB;
const
{ TODO : В дальнейшем эти константы оформить в виде ресурсов и вынести в соответсвующий модуль }
sCloseValidError = 'Ошибка. Не все требуемые поля заполнены!';
sReqValue = 'Поле %s. Требуется значение';
type type
{ TValidateItem } { TValidateItem }
@@ -100,13 +95,14 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
function CheckCloseForm:boolean; function CheckCloseForm:boolean;
function ByControl(AControl: TWinControl):TValidateItem;
published published
property ErrorMsgCaption:string read FErrorMsgCaption write FErrorMsgCaption; property ErrorMsgCaption:string read FErrorMsgCaption write FErrorMsgCaption;
property Items:TValidateItems read GetItems write SetItems; property Items:TValidateItems read GetItems write SetItems;
end; end;
implementation implementation
uses LCLType, StdCtrls, DbCtrls, typinfo, ComCtrls, ExtCtrls; uses LCLType, StdCtrls, DbCtrls, typinfo, ComCtrls, ExtCtrls, rxconst;
{ TValidateItems } { TValidateItems }
@@ -319,6 +315,22 @@ begin
Result:=true; Result:=true;
end; end;
function TRxCloseFormValidator.ByControl(AControl: TWinControl): TValidateItem;
var
i:integer;
begin
Result:=nil;
for i:=0 to FItems.Count - 1 do
begin
if FItems[i].FControl = AControl then
begin
Result:=FItems[i];
exit;
end;
end;
raise Exception.CreateFmt(sExptControlNotFound, [Name]);
end;
function TRxCloseFormValidator.GetItems: TValidateItems; function TRxCloseFormValidator.GetItems: TValidateItems;
begin begin
Result:=FItems; Result:=FItems;

View File

@@ -55,24 +55,24 @@ const
crHand = TCursor(14000); crHand = TCursor(14000);
crDragHand = TCursor(14001); crDragHand = TCursor(14001);
const //const
{ TBitmap.GetTransparentColor from GRAPHICS.PAS uses this value } //{ TBitmap.GetTransparentColor from GRAPHICS.PAS uses this value }
PaletteMask = $02000000; // PaletteMask = $02000000;
resourcestring resourcestring
sBrowse = 'Browse'; sBrowse = 'Browse';
sDefaultFilter = 'All files (*.*)|*.*'; sDefaultFilter = 'All files (*.*)|*.*';
sDateDlgTitle = 'Select a Date'; sDateDlgTitle = 'Select a Date';
sNextYear = 'Next Year|'; sNextYear = 'Next Year|';
sNextMonth = 'Next Month|'; sNextMonth = 'Next Month|';
sPrevYear = 'Previous Year|'; sPrevYear = 'Previous Year|';
sPrevMonth = 'Previous Month|'; sPrevMonth = 'Previous Month|';
sNotImplemented = 'Function not yet implemented'; sNotImplemented = 'Function not yet implemented';
sFileNotExec = 'File specified is not an executable file, dynamic-link library, or icon file'; sFileNotExec = 'File specified is not an executable file, dynamic-link library, or icon file';
sLoadLibError = 'Could not load ''%s'' library'; sLoadLibError = 'Could not load ''%s'' library';
sDetails = 'Details'; sDetails = 'Details';
sWindowsIcoFiles = 'Windows Ico files (*.ico)|*.ico|All files (*.*)|*.*'; sWindowsIcoFiles = 'Windows Ico files (*.ico)|*.ico|All files (*.*)|*.*';
sToCurDate = 'Set current date'; sToCurDate = 'Set current date';
//TDualListDialog //TDualListDialog
SDualListSrcCaption = 'Source'; SDualListSrcCaption = 'Source';
@@ -116,13 +116,13 @@ resourcestring
{ TRxHistoryNavigator } { TRxHistoryNavigator }
sHistoryDesc = 'History - "%s"'; sHistoryDesc = 'History - "%s"';
{ RxCloseFormValidator }
sCloseValidError = 'Error. Expected vailes...';
sReqValue = 'Error. Expected value for filed %s.';
sExptControlNotFound = 'Control not found in validate %s.';
implementation implementation
uses Forms;
{initialization
Screen.Cursors[crHand] := LoadCursor(hInstance, 'RX_HANDCUR');
Screen.Cursors[crDragHand] := LoadCursor(hInstance, 'RX_DRAGCUR'); }
end. end.