怎樣判斷文本框輸入的是hh:mm:ss 格式?
我在網上查的資料 說要這樣修改,可我不太喜歡這個方式。因為它有異常彈出框。
  try   
    StrToDate(wwDB1Edit1.Text)   
  Except   
    showmessage('輸入的不是時間格式'):
  end;請問各位大俠,有沒有好的辦法?

解决方案 »

  1.   

    异常弹出框只会在Delpi的IDE环境中出现, 直接执行编译生成.EXE文件时是不会有异常弹出框的。
      

  2.   

    你也可以换用 TryStrToTime 函数,这个函数不会抛出异常的。
      

  3.   


    var
      dt:TDateTime;
    begin
      TryStrToDate(wwDB1Edit1.Text,dt);
    end;
      

  4.   

    这样行不,判断文本框是否有':'
    if pos(':',edit1.text)=0 then 错误.
    不知道可以不,呵呵.
      

  5.   

    strToTime,报错就不是,不错报就是的
      

  6.   

    謝謝3樓的答案,不過用的應該TryStrTotime因為時間格式是:hh:mm:ss
      

  7.   


    现写一个吧,如有瑕疵之处,请多包涵
    function TForm1.IsTime(str: string): Boolean;
    var
      list:TStringList;
      i,num:integer;
    begin
      Result := True;
      list := TStringList.Create;
      try
        list.Delimiter := ':';
        list.DelimitedText := str;
        if list.Count <> 3 then
        begin
          Result := False;
          Exit;
        end;
        num := StrToIntDef(list.Strings[0],-1);
        if (num<0) or (num>24) then
        begin
          Result :=False;
          Exit;
        end;
        num := StrToIntDef(list.Strings[1],-1);
        if (num<0) or (num>59) then
        begin
          Result :=False;
          Exit;
        end;
        num := StrToIntDef(list.Strings[2],-1);
        if (num<0) or (num>59) then
        begin
          Result :=False;
          Exit;
        end;
      finally
        list.Free;
      end;
    end;