Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Could not convert variant of type (Null) into type (Integer) (https://www.clubdelphi.com/foros/showthread.php?t=71091)

Alejo15x 30-11-2010 07:19:02

Could not convert variant of type (Null) into type (Integer)
 
Hola!

Tengo un problemita con el cual nunca eh lidiado.
Es en sistemas XML, en el cual estoy usando un entero, pero aveces cierta función no existe osea NULA, de modo que no encuentra el entero y me tira error.

Código:

Could not convert variant of type (Null) into type (Integer)
Código Delphi [-]
    case OutfitsList.Outfit[tempOutfitId].Premium of
      0 :
        boolPremiumOutfit.Checked := false;
      1 :
        boolPremiumOutfit.Checked := true;
    end;

Estifmauin 30-11-2010 09:48:51

Simplemente, antes de entrar en el case, comprueba si el valor es nulo, y en caso afirmativo asígnale el valor x defecto:

Código Delphi [-]
if OutfitsList.Outfit[tempOutfitId].Premium = NULL then
    boolPremiumOutfit.Checked := false //el valor x por defecto
else
    // entras en el case
para evaluar la constante NULL, debes incluir uses variant, aunque supongo que ya lo tienes.

OJO: compara con NULL, no con nil. Son cosas distintas.

Neftali [Germán.Estévez] 30-11-2010 17:35:50

También puedes utilizar la función VarIsNull() especficamente diseñada para ello.

Código Delphi [-]
  if VarIsNull(OutfitsList.Outfit[tempOutfitId].Premium ) then begin

    // lo que sea si es nulo
    ...
  end
  else begin
    case OutfitsList.Outfit[tempOutfitId].Premium of
      0 :
        boolPremiumOutfit.Checked := false;
      1 :
        boolPremiumOutfit.Checked := true;
    end;
  end;


La franja horaria es GMT +2. Ahora son las 22:11:13.

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