Delphi Inputbox,InputQuery用法


Delphi :InputQuery,InputBox用法及區別

function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
InputQuery返回值為是否點了OK 輸入的字符串放在了變量Value中

function InputBox(const ACaption, APrompt, ADefault: string): string;
inputBox返回值是字符串,也就是輸入的字符串

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
//點擊了OK按鈕后,則
if InputQuery('標題','提示字符',s) then
begin
if s<>'' then //如果輸入不為空則
   showmessage(s);
end;

 


end;

procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
begin
s:=InputBox('標題','提示字符',s);
if s<>'' then
showmessage(s);
end;

Delphi通過自定義消息自定義Inputbox,使其支持掩碼並修改按鈕的caption

首先自定義一個消息ID

const
InputBoxMessage = WM_USER + 200;

接着聲明並實現該消息的處理過程

procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;//聲明

procedure Tfrm.InputBoxSetPasswordChar(var Msg: TMessage);//實現
var
hInputForm, hEdit, hButton: HWND;
begin
hInputForm := Screen.Forms[0].Handle;
if (hInputForm <> 0) then
begin
    hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
    SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
      // Change button text:
    hButton := FindWindowEx(hInputForm, 0, 'TButton', 'Cancel');
    SendMessage(hButton, WM_SETTEXT,0, Integer(PChar('取消')));
    hButton := FindWindowEx(hInputForm, 0, 'TButton', 'OK');
    SendMessage(hButton, WM_SETTEXT,0, Integer(PChar('確定')));
end;
end;

 

使用自定義后的InputBox

PostMessage(Handle, InputBoxMessage, 0, 0);
InputBox('請設置解鎖密碼','請設置解鎖密碼(不能為空):','');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM