事情很简单,我先定义了这么一个函数:function TFormUseField.IsTimeConflict(timeBegin,timeEnd:TDateTime):boolean;
begin

end;
然后调用的时候:beginTime:= DateTimePicker1.DateTime;
endTime:= DateTimePicker1.DateTime+(StrToFloat(Edit2.Text))/24.0; ///////////
if IsTimeConflict(beginTime,endTime)=true then
  begin
    ShowMessage('你启用的场地与预订有冲突!');
    exit;
  end;当我在Edit2中输入小数时,怎么也执行不过去!有如下几点不解:
1。当我在Edit2中输入整数的时候可以执行,但输入小数的时候就不行了。
2。我把加注释的那一句改为 
endTime:= DateTimePicker1.DateTime+(StrToFloat('0.5'))/24.0;
这样却又可以执行!
3.我不改上面那一行,但不调用下面那个函数,也可以执行!我高不清楚怎么回事,写程序也几年了,只是没有用Delphi.

解决方案 »

  1.   

    没看出有什么问题...也许Edit2.Text有什么东西输入的不对吧
      

  2.   

    用这个测一下:
    var
    Tmp:Extended;
    begin
    TMp:=StrToFloatDef(edit2.text,0);
             if Tmp=0 then 
                  showmessage('输入数据有误,请检查');
    end;
      

  3.   

    我用上面这段代码测试过了,输入小数(0.1)的时候也出错:提示如下:'0.1' not a valid integer value !那个ShowMessage根本就没有出来就中止了!怎么回事啊?
      

  4.   

    你是不是还定义了什么验证过程,仿佛问题不是处在你这段代码上,这样,将那个edit2删掉,重新建立一个,再将这段代码连上去试试
      

  5.   

    我将Edit2删了,又重新拖了一个过去,还是不行啊真是郁闷,怎么会出这种问题啊
      

  6.   

    真是郁闷!还是第三者次写Delphi程序,遇到这种怪问题!
      

  7.   

    下面是 IsTimeConflict 函数的实现,我也贴出来,请高手帮我分析!
    function TFormUseField.IsTimeConflict(timeBegin,timeEnd:TDateTime):boolean;
    begin
      adoquery1.Close;
      adoQuery1.sql.Clear;
      //选出项目号和场地号相同并且开始时间比当前时间晚的记录
      adoquery1.SQL.Add('select beginTime,endTime FROM fieldRecord where projectID=:ProjectID and fieldNum=:fieldNum and beginTime>:curTime');
      ADOQuery1.Parameters.ParamByName('ProjectID').Value := ProjectID;
      ADOQuery1.Parameters.ParamByName('fieldNum').Value := StrToInt(Edit2.Text);
      ADOQuery1.Parameters.ParamByName('curTime').Value := Now;
      adoQuery1.open;
      while not adoQuery1.Eof do
      begin
        //如果 beginTime落在某个预订区间内
        if (timeBegin>adoQuery1.FieldByName('beginTime').AsDateTime) and (timeBegin<adoQuery1.FieldByName('endTime').AsDateTime) then
        begin
          IsTimeConflict:=true;
          exit;
        end;
        //如果 endTime落在某个预订区间内
        if (timeEnd>adoQuery1.FieldByName('beginTime').Value) and (timeEnd<adoQuery1.FieldByName('endTime').Value) then
        begin
          IsTimeConflict:=true;
          exit;
        end;
      end;
      IsTimeConflict:=false;
    end;
      

  8.   

    下面是 IsTimeConflict 函数的实现,我也贴出来,请高手帮我分析!
    function TFormUseField.IsTimeConflict(timeBegin,timeEnd:TDateTime):boolean;
    begin
      adoquery1.Close;
      adoQuery1.sql.Clear;
      //选出项目号和场地号相同并且开始时间比当前时间晚的记录
      adoquery1.SQL.Add('select beginTime,endTime FROM fieldRecord where projectID=:ProjectID and fieldNum=:fieldNum and beginTime>:curTime');
      ADOQuery1.Parameters.ParamByName('ProjectID').Value := ProjectID;///看看清楚下面这一行
      ADOQuery1.Parameters.ParamByName('fieldNum').Value := StrToInt(Edit2.Text);
    /////  ADOQuery1.Parameters.ParamByName('curTime').Value := Now;
      adoQuery1.open;
      while not adoQuery1.Eof do
      begin
        //如果 beginTime落在某个预订区间内
        if (timeBegin>adoQuery1.FieldByName('beginTime').AsDateTime) and (timeBegin<adoQuery1.FieldByName('endTime').AsDateTime) then
        begin
          IsTimeConflict:=true;
          exit;
        end;
        //如果 endTime落在某个预订区间内
        if (timeEnd>adoQuery1.FieldByName('beginTime').Value) and (timeEnd<adoQuery1.FieldByName('endTime').Value) then
        begin
          IsTimeConflict:=true;
          exit;
        end;
      end;
      IsTimeConflict:=false;
    end;