全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2537
推到 Plurk!
推到 Facebook!

◆◇◆◇◆◇請問在InputQuery輸入框裏,如何限制輸入的是數字?

尚未結案
UpBoy
一般會員


發表:4
回覆:7
積分:2
註冊:2003-03-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-11 09:01:33 IP:210.120.xxx.xxx 未訂閱
請問在InputQuery輸入框裏,如何限制輸入的是數字,而且指定最大最小值? 在BCB幫助中找到有這樣的函數: extern PACKAGE bool __fastcall InputQuery(const WideString ACaption, const WideString APrompt, int &Value, int Min = std::numeric_limits::min(), int Max = std::numeric_limits::max(), int Increment = 1); 但我不知道怎麽用,請各位大大指點一下。
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-11 10:02:45 IP:210.241.xxx.xxx 未訂閱
怪了,我的InputQuery,只有三個參數如下 extern PACKAGE bool __fastcall InputQuery(const AnsiString ACaption, const AnsiString APrompt, AnsiString &Value); 而且help裏面也說到 Call InputQuery to bring up an input dialog box ready for the user to enter a string in its edit box. 所以我想,你要不要換個方式呢?
UpBoy
一般會員


發表:4
回覆:7
積分:2
註冊:2003-03-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-11 10:13:15 IP:210.120.xxx.xxx 未訂閱
引言: 怪了,我的InputQuery,只有三個參數如下 extern PACKAGE bool __fastcall InputQuery(const AnsiString ACaption, const AnsiString APrompt, AnsiString &Value); 而且help裏面也說到 Call InputQuery to bring up an input dialog box ready for the user to enter a string in its edit box. 所以我想,你要不要換個方式呢?
呵呵呵。幫助文檔裏面可有很多個InputQuery的哦: extern PACKAGE bool __fastcall InputQuery(constWideString ACaption, const WideString APrompt, WideString &Value); extern PACKAGE bool __fastcall InputQuery(const WideString ACaption, const WideString APrompt, AnsiString &Value); extern PACKAGE bool __fastcall InputQuery(const WideString ACaption, const WideString APrompt, double &Value, double Min = std::numeric_limits::min(), double Max = std::numeric_limits::max(), int Decimals = 1); extern PACKAGE bool __fastcall InputQuery(const WideString ACaption, const WideString APrompt, int &Value, int Min = std::numeric_limits::min(), int Max = std::numeric_limits::max(), int Increment = 1); 你說的應該是第二個吧! 而且help裏面也說到: Call InputQuery to bring up an input dialog box ready for the user to enter a string, double, or integer in its edit box. 可我就是不知道怎麽用!
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-06-11 10:46:12 IP:210.241.xxx.xxx 未訂閱
首先 我知道您是用BCB6對吧 因為BCB5只有我說的一種InputQuery 我後來用BCB6試了一下 include QDialogs.hpp後,就可以看到
UpBoy
一般會員


發表:4
回覆:7
積分:2
註冊:2003-03-17

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-06-11 11:18:09 IP:210.120.xxx.xxx 未訂閱
引言: 首先 我知道您是用BCB6對吧 因為BCB5只有我說的一種InputQuery 我後來用BCB6試了一下 include QDialogs.hpp後,就可以看到
呵呵呵。是的,我居然忘了include了 可是,加上後,居然出現了其他的暴多的錯誤: [ >
turboted
版主


發表:95
回覆:754
積分:452
註冊:2002-07-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-06-14 16:34:21 IP:61.66.xxx.xxx 未訂閱
BCB6 更新程式裏面,有變更過這個相關檔案 請問您有UPDATE嗎,我的是BCB6 UP4 一切都滿正常的
UpBoy
一般會員


發表:4
回覆:7
積分:2
註冊:2003-03-17

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-06-16 08:55:02 IP:210.120.xxx.xxx 未訂閱
引言: BCB6 更新程式裏面,有變更過這個相關檔案 請問您有UPDATE嗎,我的是BCB6 UP4 一切都滿正常的
你好! 我也用的是BCB6 UP4 啊~! 在.h中include QDialogs.hpp後,compile至 class TForm1 : public TForm { __published: // IDE-managed Components TStringGrid *StringGrid1; TStatusBar *StatusBar1; TButton *Button1; ... private: // User declarations public: // User declarations ... }; 就出這樣的錯了!
andychang1690
資深會員


發表:20
回覆:694
積分:442
註冊:2003-03-14

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-09-16 12:34:36 IP:221.169.xxx.xxx 未訂閱
UpBoy:於
http://delphi.ktop.com.tw/topic.php?topic_id=51948
【BCB】【問題】請問要如何限制"InputBox"輸入資料類型?? 
我想把InputBox中輸入資料類型限制為數字!!
請問各位大大有辦法辦到嗎??
你倆問題一樣我再Post一次
參考方法:
InputBox 可以做到應用面看你自己處理,
原Vcl\Source\dialogs.pas 不要動,也不要改
將dialogs.pas copy回你BCB專案檔案下
開啟你的BCB專案目錄下dialogs.pas
找到function InputQuery裡的注意紅字部分是你要加入或修改的部分!
function InputQuery(const ACaption, APrompt: string;
  var Value: string): Boolean;
var
  Form: TForm;
  Prompt: TLabel;
  Edit: TEdit;
  fstyle: dWord;  //
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
  Result := False;
  Form := TForm.Create(Application);
  with Form do
    try
      Canvas.Font := Font;
      DialogUnits := GetAveCharSize(Canvas);
      BorderStyle := bsDialog;
      Caption := ACaption;
      ClientWidth := MulDiv(180, DialogUnits.X, 4);
      ClientHeight := MulDiv(63, DialogUnits.Y, 8);
      Position := poScreenCenter;
      Prompt := TLabel.Create(Form);
      with Prompt do
      begin
        Parent := Form;
        Left := MulDiv(8, DialogUnits.X, 4);
        Top := MulDiv(8, DialogUnits.Y, 8);
        Width := 160; // 保證中文顯示沒問題
        AutoSize := False;
        Caption := APrompt;
      end;
      Edit := TEdit.Create(Form);
      with Edit do
      begin
        Parent := Form;
        Left := Prompt.Left;
        Top := MulDiv(19, DialogUnits.Y, 8);
        Width := MulDiv(164, DialogUnits.X, 4);
        MaxLength := 255;
//        PasswordChar:='*'; // 密碼方式輸入
        Text := Value;
        SelectAll;
      end;
      fstyle := GetWindowLong(Edit.Handle, GWL_STYLE);   //
      SetWindowLong(Edit.Handle, GWL_STYLE, fstyle or ES_NUMBER);  //
      ButtonTop := MulDiv(41, DialogUnits.Y, 8);
      ButtonWidth := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '確定'; // SMsgDlgOK; // 改成中文
        ModalResult := mrOk;
        Default := True;
        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;
      with TButton.Create(Form) do
      begin
        Parent := Form;
        Caption := '取消'; SMsgDlgCancel; // 改成中文
        ModalResult := mrCancel;
        Cancel := True;
        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;
      if ShowModal = mrOk then
      begin
        Value := Edit.Text;
        Result := True;
      end;
    finally
      Form.Free;
    end;
end;
這是以用API實現數值型Edit!
只要你的這隻同目錄下的dialogs.pas 加入你的project即可
記著你的專案檔案只要
project-> add BCB專案目錄下dialogs.pas
程式裡不要Include dialogs.pas
請參考!
Andy Chang
------
Andy Chang
系統時間:2024-05-19 4:49:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!