我想问问,我现在想向数据库中写入小数的数据,这个数据是用Tedit输入的,我现在用的是ParamByName的写法.因为数据库中的字段定义的是numeric,所以要写小数的数据.
if edtSeg_Length.text<>'' then
  ParamByName('seg_length').asfloat:=strtofloat(edtSeg_Length.text)
else
  ParamByName('seg_length').asfloat:=Null;
这样的写法对吗?我运行的时候,总是出错.正确的写法是什么样的?谢谢各位了!!

解决方案 »

  1.   

    将ParamByName换成FieldByName试试。
      

  2.   

    if edtSeg_Length.text<>'' then
      ParamByName('seg_length').asfloat:=strtofloat(edtSeg_Length.text);
    else部分不要了,你试下看.
      

  3.   

    else部分不能直接这样子赋值,而需要的是对Variant类型的Value属性值置为Null.
      

  4.   

    if edtSeg_Length.text<>'' then
      ParamValues['seg_length']:=strtofloat(edtSeg_Length.text) //strtofloat可能会出错
    else
      ParamValues['seg_length']:=Null;再给你个函数,就可以使输入框只输入数字,并限制长度、小数位数等procedure MxFormatKeyPress(Text:string;SelStart,SelLength:integer;
    var Key:Char;EditType:integer;Digits:integer);
    begin
    if (Key=#27) or (Key=#8) or (EditType=1) then exit;
    if EditType=2 then
       if not (Key in ['0'..'9','+','-'] ) then Key:=#0;
    if EditType=3 then
       if not (Key in ['0'..'9','+','-','.'] ) then Key:=#0;
    //控制+-
    if (Key ='-') or (Key='+' ) then
     begin
      if ((Pos('-',Text) > 0) or (Pos('+',Text) > 0 )) and
              (SelLength=0 ) then Key:=#0;
      if SelStart > 0 then Key:=#0;
     end;
    //控制.
    if (Key = '.') and (EditType=3 ) then
     begin
      if (Pos('.',Text) > 0) and (not((SelStart=Pos('.',Text) ))) then Key:=#0;
      if SelStart=0 then Key:=#0;
      if (Digits>0) and (SelStart+SelLength>0) and (EditType=3) then exit;
     end;
    if (pos('.',Text )>0 ) and (SelStart>=pos('.',Text)) then
        if length(Text)-pos('.',Text )>=Digits then Key:=#0;
    end;