change Null values with 0

hi
i have a question about null values
i have 20 EditBoxes on my form, i wanna write a code that it change my EditBoxes value with 0
i mean if values were NULL it change to 0
in Oracle there was a function that i use it like this >>>  NVL(Variable,0)
Is there any function like this in Delphi?
I dont want use some code like this>> if a is null then a:=0;
Mahsa60Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RadikalQ3Commented:
Hi!, Mahsa60

if DBEdit1.Field.IsNull then...
esoftbgCommented:
Hi Masha, the next code will check and change all the EditBoxes on the Form:

var
  I:      Integer;
begin
  for I := 0 to ComponentCount-1 do
    if (Components[I] is TEdit) then
      if (Components[I] as TEdit).Text = '' then
        (Components[I] as TEdit).Text := '0';
end;

Emil
esoftbgCommented:
You may change the Field declarationss in the Database to be:
default 0
This way you will avoid NULL values about these Fields
;-))

Emil
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

kretzschmarCommented:
not clear if TEdits ot TDBEdits are meant,
but if the values are coming from a database,
then use the onGetText/onSetText-events of the associated TFields
to map values like NULL

meikl ;-)
RadikalQ3Commented:
A TEdit can not have a NULL value no? :)
Mahsa60Author Commented:
no no
sorry if i didnt explain clearly
this is my code for send Data to Table >>>
with D_Module.T_Pump_Desc do
    begin
        append;
        FieldByName('Tag_No').AsString:=Edit1.Text;
        FieldByName('Manufacture').AsString:=Edit16.Text;
        FieldByName('Type').AsString:=Edit17.Text;
        FieldByName('Serial_No').AsString:=Edit18.Text;
        FieldByName('MESC').AsString:=Edit19.Text;
        FieldByName('PartList_Draw').AsString:=Pic_Path1;
        FieldByName('Opr_Liquid').AsString:=Edit2.Text;
{1}        FieldByName('Opr_Flow_Norm').AsFloat:=StrToFloat(Edit3.Text);
{1}        FieldByName('Opr_Flow_Rate').AsFloat:=StrToFloat(Edit8.Text);
{1}        FieldByName('Opr_Temperture').AsFloat:=StrToFloat(Edit4.Text);
{1}        FieldByName('Opr_Press_Dischange').AsFloat:=StrToFloat(Edit5.Text);
{1}        FieldByName('Opr_Press_Suction').AsFloat:=StrToFloat(Edit9.Text);
       post;
end ;//end with

when i run this codes i get error on lines {1}  bcz sometimes i forget fill these Editboxes
i wanna change Null Data to ziro with a function just for these Boxes


RadikalQ3Commented:
use
StrToFloatDef(Edit3.Text,0.0);

instead of StrToFloat
kretzschmarCommented:
if Edit3.Text <> '' then
  FieldByName('Opr_Flow_Norm').AsFloat:=StrToFloat(Edit3.Text);
else
  FieldByName('Opr_Flow_Norm').AsFloat:=0;

or

function CheckFloatValue(AString : String) : Double;
begin
  try
    Result := StrToFloat(AString);
  except
    Result := 0;
  end;
end;

use like

FieldByName('Opr_Flow_Norm').AsFloat:=CheckFloatValue(Edit3.Text);

meikl ;-)
RadikalQ3Commented:
And... your problem is not for a NULL value, the problem is a incorrect String to Float conversion, because the string is empty...
esoftbgCommented:
You may set all the Edit boxes (which need this check for NULL) property Tag --> 48 (as usual it is 0)
This way Edit3, Edit8, Edit4, Edit5 and Edit9 have a property Tag value 48
You will avoid the exception from:    StrToFloat(Edit#.Text);

var
  I:      Integer;
begin
  for I := 0 to ComponentCount-1 do
    if (Components[I] is TEdit) then
      if ((Components[I] as TEdit).Tag = 48) then
        if ((Components[I] as TEdit).Text = '') then
          (Components[I] as TEdit).Text := '0';

  with D_Module.T_Pump_Desc do
  begin
    append;
    FieldByName('Tag_No').AsString:=Edit1.Text;
    FieldByName('Manufacture').AsString:=Edit16.Text;
    FieldByName('Type').AsString:=Edit17.Text;
    FieldByName('Serial_No').AsString:=Edit18.Text;
    FieldByName('MESC').AsString:=Edit19.Text;
    FieldByName('PartList_Draw').AsString:=Pic_Path1;
    FieldByName('Opr_Liquid').AsString:=Edit2.Text;
{1} FieldByName('Opr_Flow_Norm').AsFloat:=StrToFloat(Edit3.Text);
{1} FieldByName('Opr_Flow_Rate').AsFloat:=StrToFloat(Edit8.Text);
{1} FieldByName('Opr_Temperture').AsFloat:=StrToFloat(Edit4.Text);
{1} FieldByName('Opr_Press_Dischange').AsFloat:=StrToFloat(Edit5.Text);
{1} FieldByName('Opr_Press_Suction').AsFloat:=StrToFloat(Edit9.Text);
   post;
  end ;//end with
end;

Emil
RadikalQ3Commented:
Is not necessary the test for an empty value... just use StrToFloatDef...

with D_Module.T_Pump_Desc do
    begin
        append;
        FieldByName('Tag_No').AsString:=Edit1.Text;
        FieldByName('Manufacture').AsString:=Edit16.Text;
        FieldByName('Type').AsString:=Edit17.Text;
        FieldByName('Serial_No').AsString:=Edit18.Text;
        FieldByName('MESC').AsString:=Edit19.Text;
        FieldByName('PartList_Draw').AsString:=Pic_Path1;
        FieldByName('Opr_Liquid').AsString:=Edit2.Text;
{1}        FieldByName('Opr_Flow_Norm').AsFloat:=StrToFloatDef(Edit3.Text,0);
{1}        FieldByName('Opr_Flow_Rate').AsFloat:=StrToFloatDef(Edit8.Text,0);
{1}        FieldByName('Opr_Temperture').AsFloat:=StrToFloatDef(Edit4.Text,0);
{1}        FieldByName('Opr_Press_Dischange').AsFloat:=StrToFloatDef(Edit5.Text,0);
{1}        FieldByName('Opr_Press_Suction').AsFloat:=StrToFloatDef(Edit9.Text,0);
       post;
end ;//end with

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mahsa60Author Commented:
tanx to all friends
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.