Código
Retorna FALSE se naum houver conteúdo ou TRUE casa haja valor.
Nota: valida também datas, inclusive a data maluca do DELPHI.
{*****
* Empty( xValue );
* Retorna True se a variável está vazia.
*
* Autor: Jociel Eloy de Almeida
*}
function Empty(xValue: Variant): Boolean;
var
sTmp: String;
iDia, iMes, iAno: Word;
begin
{Pré-Definição do Retorno}
Result := False;
if xValue = Null then begin
Result := True;
Exit;
end;
if VarType(xValue) = VarEmpty then
Result := True;
if VarType(xValue) = varNull then
Result := True;
if VarType(xValue) = varSmallInt then
Result := (xValue = 0);
if VarType(xValue) = varInteger then
Result := (xValue = 0);
if VarType(xValue) = varSingle then
Result := (xValue = 0);
if VarType(xValue) = varDouble then
Result := (xValue = 0);
if VarType(xValue) = varCurrency then
Result := (xValue = 0);
if VarType(xValue) = varDate then begin
Result := (xValue = Null);
if not Result then begin
DecodeDate(xValue,iAno,iMes,iDia);
if ((iDia = 30) and (iMes = 12) and (iAno = 1899)) then
Result := True;
end;
if not Result then begin
sTmp := DateToStr(xValue);
sTmp := StrTran(sTmp,'/','');
sTmp := StrTran(sTmp,'-','');
sTmp := StrTran(sTmp,'.','');
Result := Empty(sTmp);
end;
end;
if VarType(xValue) = varString then
Result := (Len(StrTran(xValue, ' ', '')) = 0);
if VarType(xValue) = varOleStr then
Result := (xValue = Null);
if VarType(xValue) = varDispatch then
Result := (xValue = Null);
if VarType(xValue) = varByte then
Result := (xValue = Null);
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009