我有
var objeto:TDateEdit; ...
如果我更改as TDateEdit
代码:
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TDateEdit).name )
并使用这个:
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as objeto).name)
代码有效....但我需要改变
objeto := TDBEdit;
我需要一种方法来更改此变量类型以减少我将使用的代码
If (FORMULARIO.Components[i] is TDateEdit) then objeto := TDateEdit
If (FORMULARIO.Components[i] is TDBLookupComboBox) then objeto := TDBLookupComboBox
但变量是
var objeto: TDateEdit;
如何在不重复每种对象类型的代码的情况下做到这一点?
Function ValidaCampoObrigatorio(): boolean;
var i,PrimeiroCampo,ii,indexOfItem:Integer;
var MSGaglutinada,TIPO:string;
var NOMEcampo : variant ;
var objeto:TDateEdit ;
var VALIDOU:boolean;
begin
CorERRO:=RGB(255,218,185);
CorCertO:= 12582911;//$FF000005;
Result := false;
MSGaglutinada:='';
PrimeiroCampo:=-1;
tipo:='';
NOMEcampo:='';
for i := 0 to FORMULARIO.ComponentCount -1 do
begin
if (FORMULARIO.Components[i] is TDateEdit) then
begin
indexOfItem := -1;
ii:=0;
for ii := Low(CAMPOSnoBANCO) to High(CAMPOSnoBANCO) do
//LOCALIZANDO DENTRO da matriz
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TDateEdit).name ) then
begin
BREAK;
end;
VALIDOU:=True;
if EhRequerido[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if((FORMULARIO.Components[i] as TDateEdit).text = '')then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDateEdit).Name)+' não pode ser NULO'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if EhEMAIL[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if ValidEmail((FORMULARIO.Components[i] as TDateEdit).text) = False then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDateEdit).Name)+' DEVE ser válido'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end ;
if EhData[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if DataValida((FORMULARIO.Components[i] as TDateEdit).text)=false then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDateEdit).Name)+' DEVE uma data Válida'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDateEdit).Color:=corERRO; VALIDOU:=false ;
end
else
begin
if (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)])<=StrToDate((FORMULARIO.Components[i] as TDateEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDateEdit).Name)+' não pode maior ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if (OperadorDataMaior[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamaior[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)])>=StrToDate((FORMULARIO.Components[i] as TDateEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDateEdit).Name)+' não pode menor ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDateEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
end;
end ;
if VALIDOU=true then
begin
(FORMULARIO.Components[i] as TDateEdit).Color:= CorCertO;
end;
end;
if (FORMULARIO.Components[i] is TDBEdit) then
begin
indexOfItem := -1;
ii:=0;
for ii := Low(CAMPOSnoBANCO) to High(CAMPOSnoBANCO) do
//LOCALIZANDO DENTRO da matriz
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TDBEdit).name ) then
begin
BREAK;
end;
VALIDOU:=True;
if EhRequerido[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)]=true then
begin
if((FORMULARIO.Components[i] as TDBEdit).field.AsString = '')then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBEdit).Name)+' não pode ser NULO'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if EhEMAIL[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)]=true then
begin
if ValidEmail((FORMULARIO.Components[i] as TDBEdit).text) = False then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBEdit).Name)+' DEVE ser válido'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBEdit).Color:=corERRO; VALIDOU:=false ;
end;
end ;
if EhData[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)]=true then
begin
if DataValida((FORMULARIO.Components[i] as TDBEdit).text)=false then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBEdit).Name)+' DEVE uma data Válida'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBEdit).Color:=corERRO; VALIDOU:=false ;
end
else
begin
if (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)])<=StrToDate((FORMULARIO.Components[i] as TDBEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBEdit).Name)+' não pode maior ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if (OperadorDataMaior[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamaior[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)])>=StrToDate((FORMULARIO.Components[i] as TDBEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBEdit).Name)+' não pode menor ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
end;
end ;
if VALIDOU=true then
begin
(FORMULARIO.Components[i] as TDBEdit).Color:= CorCertO;
end;
end;
if (FORMULARIO.Components[i] is TDBLookupComboBox) then
begin
indexOfItem := -1;
ii:=0;
for ii := Low(CAMPOSnoBANCO) to High(CAMPOSnoBANCO) do
//LOCALIZANDO DENTRO da matriz
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).name ) then
begin
BREAK;
end;
VALIDOU:=True;
if EhRequerido[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)]=true then
begin
if((FORMULARIO.Components[i] as TDBLookupComboBox).field.AsString = '')then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBLookupComboBox' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).Name)+' não pode ser NULO'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:=corERRO; VALIDOU:=false ;
end;
end;
if EhEMAIL[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)]=true then
begin
if ValidEmail((FORMULARIO.Components[i] as TDBLookupComboBox).text) = False then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBLookupComboBox' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).Name)+' DEVE ser válido'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:=corERRO; VALIDOU:=false ;
end;
end ;
if EhData[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)]=true then
begin
if DataValida((FORMULARIO.Components[i] as TDBLookupComboBox).text)=false then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBLookupComboBox' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).Name)+' DEVE uma data Válida'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:=corERRO; VALIDOU:=false ;
end
else
begin
if (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)])<=StrToDate((FORMULARIO.Components[i] as TDBLookupComboBox).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBLookupComboBox' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).Name)+' não pode maior ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:=corERRO; VALIDOU:=false ;
end;
end;
if (OperadorDataMaior[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamaior[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)])>=StrToDate((FORMULARIO.Components[i] as TDBLookupComboBox).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBLookupComboBox' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBLookupComboBox).Name)+' não pode menor ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBLookupComboBox).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:=corERRO; VALIDOU:=false ;
end;
end;
end;
end ;
if VALIDOU=true then
begin
(FORMULARIO.Components[i] as TDBLookupComboBox).Color:= CorCertO;
end;
end;
if (FORMULARIO.Components[i] is TDBDateEdit) then
begin
indexOfItem := -1;
ii:=0;
for ii := Low(CAMPOSnoBANCO) to High(CAMPOSnoBANCO) do
//LOCALIZANDO DENTRO da matriz
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TDBDateEdit).name ) then
begin
BREAK;
end;
VALIDOU:=True;
if EhRequerido[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if((FORMULARIO.Components[i] as TDBDateEdit).text = '')then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBDateEdit).Name)+' não pode ser NULO'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if EhEMAIL[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if ValidEmail((FORMULARIO.Components[i] as TDBDateEdit).text) = False then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBDateEdit).Name)+' DEVE ser válido'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end ;
if EhData[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)]=true then
begin
if DataValida((FORMULARIO.Components[i] as TDBDateEdit).text)=false then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBDateEdit).Name)+' DEVE uma data Válida'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBDateEdit).Color:=corERRO; VALIDOU:=false ;
end
else
begin
if (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)])<=StrToDate((FORMULARIO.Components[i] as TDBDateEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBDateEdit).Name)+' não pode maior ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if (OperadorDataMaior[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamaior[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)])>=StrToDate((FORMULARIO.Components[i] as TDBDateEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TDBDateEdit).Name)+' não pode menor ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TDBDateEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TDBDateEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
end;
end ;
if VALIDOU=true then
begin
(FORMULARIO.Components[i] as TDBDateEdit).Color:= CorCertO;
end;
end;
//////////////////////////////////////////////////////////////
//TMaskEdit
if (FORMULARIO.Components[i] is TMaskEdit) then
begin
indexOfItem := -1;
ii:=0;
for ii := Low(CAMPOSnoBANCO) to High(CAMPOSnoBANCO) do
//LOCALIZANDO DENTRO da matriz
if UpperCase(CAMPOSnoBANCO[ii]) = UpperCase((FORMULARIO.Components[i] as TMaskEdit).name ) then
begin
BREAK;
end;
VALIDOU:=True;
if EhRequerido[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)]=true then
begin
if((FORMULARIO.Components[i] as TMaskEdit).text = '')then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TDBDateEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TMaskEdit).Name)+' não pode ser NULO'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TMaskEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if EhEMAIL[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)]=true then
begin
if ValidEmail((FORMULARIO.Components[i] as TMaskEdit).text) = False then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TMaskEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TMaskEdit).Name)+' DEVE ser válido'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TMaskEdit).Color:=corERRO; VALIDOU:=false ;
end;
end ;
if EhData[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)]=true then
begin
if DataValida((FORMULARIO.Components[i] as TMaskEdit).text)=false then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TMaskEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TMaskEdit).Name)+' DEVE uma data Válida'+ #13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TMaskEdit).Color:=corERRO; VALIDOU:=false ;
end
else
begin
if (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)])<=StrToDate((FORMULARIO.Components[i] as TMaskEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TMaskEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TMaskEdit).Name)+' não pode maior ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TMaskEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
if (OperadorDataMaior[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)] <> '') then
begin
if StrToDate(OperadorDatamaior[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)])>=StrToDate((FORMULARIO.Components[i] as TMaskEdit).text)then
begin
if PrimeiroCampo<0 then begin PrimeiroCampo:=i;TIPO:='TMaskEdit' end;
MSGaglutinada := UpperCase((FORMULARIO.Components[i] as TMaskEdit).Name)+' não pode menor ou igual à '+ (OperadorDatamenor[ansiindexstr((FORMULARIO.Components[i] as TMaskEdit).name , CAMPOSnoBANCO)])+#13#10+Trim(MSGaglutinada) ;
(FORMULARIO.Components[i] as TMaskEdit).Color:=corERRO; VALIDOU:=false ;
end;
end;
end;
end ;
if VALIDOU=true then
begin
(FORMULARIO.Components[i] as TMaskEdit).Color:= CorCertO;
end;
end;
end;
///////////////////////////////////////////////////////////
if MSGaglutinada <>'' then
begin
MSGaglutinada:=ReplaceAll(MSGaglutinada,CAMPOSnoBANCO,CAMPOSexibirCOMO,True) ;
MessageDlg('O(s) campo(s): '+#13#10+MSGaglutinada , mtWarning, [mbok],0 ) ;
if TIPO='TDBEdit' then
begin
(FORMULARIO.Components[PrimeiroCampo] as TDBEdit).SetFocus;
end
else if TIPO='TDBLookupComboBox' then
begin
(FORMULARIO.Components[PrimeiroCampo] as TDBLookupComboBox).SetFocus
end
else if TIPO='TMaskEdit' then begin
(FORMULARIO.Components[PrimeiroCampo] as TMaskEdit).SetFocus
end
else if TIPO='TDBDateEdit' then begin
(FORMULARIO.Components[PrimeiroCampo] as TDBDateEdit).SetFocus
end
else if TIPO='TDateEdit' then begin
(FORMULARIO.Components[PrimeiroCampo] as TDateEdit).SetFocus
end;
Abort;
end;
result := true;
end;
function ReplaceAll(const Subject: String;
const OldPatterns, NewPatterns: array of String;
IgnoreCase: Boolean): String;
var
ReplaceFlags: TReplaceFlags;
NewPattern: String;
I: Integer;
begin
ReplaceFlags := [rfReplaceAll];
if IgnoreCase then
Include(ReplaceFlags, rfIgnoreCase);
Result := Subject;
for I := Low(OldPatterns) to High(OldPatterns) do
begin
if I <= High(NewPatterns) then
NewPattern := NewPatterns[I]
else
NewPattern := '';
Result := StringReplace(Result, OldPatterns[I], NewPattern, ReplaceFlags);
end;
end;
function ValidEmail(email: string): boolean;
var
RegEx: TRegEx;
begin
RegEx := TRegex.Create('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]*[a-zA-Z0-9]+$');
Result := RegEx.Match(email).Success;
end;
function DataValida(StrD: string): Boolean;
var
DataDigitadaNoEdit:TDateTime;
{Testa se uma data é valida}
begin
Result := true;
try
//ShowMessage((StrD));
if (StrD<>' / / ') and (StrD <> ' / / ') and (StrD <> null) and (StrD<>'')then
begin
TryStrToDate(StrD,DataDigitadaNoEdit) ;
end
else
Begin
Result:=False;
// Abort;
end;
except
on EConvertError do Result:=False;
end;
end;
function NumeroValido(StrD: string): Boolean;
{Testa se uma data é valida}
begin
Result := true;
try
StrToDate(StrD);
except
on EConvertError do Result:=False;
end;
end;