全國最多中醫師線上諮詢網站-台灣中醫網
上鎖的討論區 上鎖的討論區 瀏覽次數:956
推到 Plurk!
推到 Facebook!

問題在哪呢?

答題得分者是:delphiwww
lmk625
一般會員


發表:14
回覆:13
積分:5
註冊:2002-03-28

發送簡訊給我
#1 發表時間:2002-11-07 18:12:45 IP:203.75.xxx.xxx 未訂閱
設定edit1的onenter事件指定為button1click,為何我的程式一開始即執行此部份,又在edit1按下enter按鍵並無作用?程式如下: procedure TForm1.Button4Click(Sender: TObject); begin //結束程式 Form1.Close; end; procedure TForm1.Button1Click(Sender: TObject); var n1: Integer; s_file, gstr : string; begin //輸入發票號碼 s_file:=Edit1.Text;// #13 #10; n1:=length(Edit1.Text); if n1=8 then //是否輸入八個數字號碼 begin if fileexists('invoice.txt') then //是否已存在此檔案 begin assignfile(sfile,'invoice.txt'); reset(sfile); //openfile if Application.MessageBox(' 確定新增這一筆資料? ',' 注意 ',MB_YESNO MB_ICONQUESTION)=IDYES then begin while not EOF(sfile) do begin readln(sfile,gstr); if gstr=s_file then //是否重覆輸入號碼 begin Application.MessageBox(' 發票號碼重覆了! ',' 錯誤訊息 ',MB_OK); Edit1.Clear; Edit1.SetFocus; closefile(sfile); Exit; end; end; closefile(sfile); assignfile(sfile,'invoice.txt'); append(sfile); writeln(sfile,s_file); closefile(sfile); end; end else if Application.MessageBox(' 無檔案"invoice.txt"存在,要新建這檔案嗎? ',' 注意 ',MB_YESNO MB_ICONQUESTION)=IDYES then begin AssignFile(sfile,'invoice.txt'); Rewrite(sfile); //建立或覆寫已存在檔案的openfile writeln(sfile,s_file); closefile(sfile); end; Edit1.Clear; end else if n1 <> 0 then Application.MessageBox(' 發票號碼輸入錯誤,長度不足 ',' 錯誤訊息 ',MB_OK MB_ICONERROR); end; procedure TForm1.FormActivate(Sender: TObject); begin Edit1.SetFocus; end;
delphiwww
資深會員


發表:145
回覆:363
積分:368
註冊:2002-03-13

發送簡訊給我
#2 發表時間:2002-11-07 19:59:51 IP:202.145.xxx.xxx 未訂閱
onenter的 event指的是進入Edit1,不是按下enter件, 你可以用在onkeypress設定 if key=#13 then    button1.setfocus; 然後將onexit的event指向button1click    
引言: 設定edit1的onenter事件指定為button1click,為何我的程式一開始即執行此部份,又在edit1按下enter按鍵並無作用?程式如下: procedure TForm1.Button4Click(Sender: TObject); begin //結束程式 Form1.Close; end; procedure TForm1.Button1Click(Sender: TObject); var n1: Integer; s_file, gstr : string; begin //輸入發票號碼 s_file:=Edit1.Text;// #13 #10; n1:=length(Edit1.Text); if n1=8 then //是否輸入八個數字號碼 begin if fileexists('invoice.txt') then //是否已存在此檔案 begin assignfile(sfile,'invoice.txt'); reset(sfile); //openfile if Application.MessageBox(' 確定新增這一筆資料? ',' 注意 ',MB_YESNO MB_ICONQUESTION)=IDYES then begin while not EOF(sfile) do begin readln(sfile,gstr); if gstr=s_file then //是否重覆輸入號碼 begin Application.MessageBox(' 發票號碼重覆了! ',' 錯誤訊息 ',MB_OK); Edit1.Clear; Edit1.SetFocus; closefile(sfile); Exit; end; end; closefile(sfile); assignfile(sfile,'invoice.txt'); append(sfile); writeln(sfile,s_file); closefile(sfile); end; end else if Application.MessageBox(' 無檔案"invoice.txt"存在,要新建這檔案嗎? ',' 注意 ',MB_YESNO MB_ICONQUESTION)=IDYES then begin AssignFile(sfile,'invoice.txt'); Rewrite(sfile); //建立或覆寫已存在檔案的openfile writeln(sfile,s_file); closefile(sfile); end; Edit1.Clear; end else if n1 <> 0 then Application.MessageBox(' 發票號碼輸入錯誤,長度不足 ',' 錯誤訊息 ',MB_OK MB_ICONERROR); end; procedure TForm1.FormActivate(Sender: TObject); begin Edit1.SetFocus; end;
系統時間:2024-05-18 17:54:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!