Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-05-2017
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.009
Poder: 20
oscarac Va por buen camino
campo vacio

Saludos
Hice esta pequeña funcion para saber si un campo de una tabla esta vacio

Function campovacio(campo: variant): boolean;
Begin
Result:= campo = '';
End;

Me funciona en texto pero en campo fecha no
He notado q a pesar de que el campo esta vacio tiene el valor de '12:00:00am' y me aparece el siguiente mensaje

Could not convert variant of type string into type date

Alguien me da una mano? O tiene alguna idea mejor?

Gracias
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita
  #2  
Antiguo 23-05-2017
Avatar de olbeup
olbeup olbeup is offline
Miembro
 
Registrado: jul 2005
Ubicación: Santiago de la Ribera (España)
Posts: 685
Poder: 19
olbeup Va camino a la fama
Hola oscarac,

El tipo campo: Variant que has definido, puede tomar cualquier tipo y valor, lo que tienes que hacer es saber de que tipo es el valor que le has pasado a la función.

Código Delphi [-]
function CampoVacio(Campo: Variant): Boolean;
begin
  case VarType(Campo) of
    varDate: Result := (YearOf(Campo) <= 1900);
    varString: Result := (Campo = '');
    var...
  end;
end;

Un saludo.

p.d.: Aquí tienes el resto de tipos.

Cita:
Returns the type code of a specified variant.

Unit

Variants

Category

Variant support routines

Delphi syntax:

function VarType(const V: Variant): TVarType;

C++ syntax:

extern PACKAGE TVarType __fastcall VarType(const Variant &V);

Description

VarType returns the type code of the given variant. The resulting value is either the type code for a custom Variant type, or it is constructed from the constants declared in the System unit.

The lower twelve bits of a variant type code (the bits defined by the varTypeMask bit mask) define the type of the variant. The varArray bit is set if the variant is an array of the given type. The varByRef bit is set if the variant is a reference to a value of the given type as opposed to an actual value.

The following table describes the meaning of each of the variant type codes defined in the System unit:

VarType Contents of variant

varEmpty The variant is Unassigned.
varNull The variant is Null.
varSmallint 16-bit signed integer (type Smallint in Delphi, short in C++ ).
varInteger 32-bit signed integer (type Integer in Delphi, int in C++).
varSingle Single-precision floating-point value (type Single in Delphi, float in C++).
varDouble Double-precision floating-point value (type double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).

varOleStr Reference to a dynamically allocated UNICODE string.
varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A variant.
varUnknown Reference to an unknown object (an IInterface or IUnknown interface pointer).
varShortInt 8-bit signed integer (type ShortInt in Delphi or signed char in C++)
varByte A Byte
varWord unsigned 16-bit value (Word)

varLongWord unsigned 32-bit value (type LongWord in Delphi or unsigned long in C++)
varInt64 64-bit signed integer (Int64 in Delphi or __int64 in C++)
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string (not COM compatible).
varAny A CORBA Any value.

The value returned by VarType corresponds to the VType field of a TVarData record.

The type of a variant can be changed using VarAsType.
__________________
Al hacer una consulta SQL, haz que los demás te entiendan y disfruten de ella, será tú reflejo de tú saber.
Responder Con Cita
  #3  
Antiguo 23-05-2017
Avatar de Caminante
Caminante Caminante is offline
Miembro
 
Registrado: oct 2010
Ubicación: Lima - Peru
Posts: 338
Poder: 14
Caminante Va camino a la fama
Hola

Tambien puedes usar las funciones varisempty o varisnull para ver si el campo esta vacio.

Si es un campo de un dataset (un TField) está el metodo isnull.

Saludos
__________________
Caminante, son tus huellas el camino y nada más; Caminante, no hay camino, se hace camino al andar.
Antonio Machado
Responder Con Cita
  #4  
Antiguo 24-05-2017
Avatar de oscarac
[oscarac] oscarac is offline
Miembro Premium
 
Registrado: sep 2006
Ubicación: Lima - Perú
Posts: 2.009
Poder: 20
oscarac Va por buen camino
se agradece
funciona
__________________
Dulce Regalo que Satanas manda para mi.....
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Campo vacío en CxGrid cmfab Varios 4 02-05-2012 14:25:27
Campo Fecha vacio en SQL oscarac OOP 3 30-08-2010 18:13:30
Reconocer Campo Vacio lKinGl Conexión con bases de datos 3 11-11-2008 16:24:22
Campo vacio en dbf lKinGl Varios 17 11-11-2008 16:21:28
un campo memo vacio? NSL94 SQL 1 25-04-2007 14:05:35


La franja horaria es GMT +2. Ahora son las 20:21:26.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi