是算法还是函数?数组? |
答題得分者是:jow
|
zhouying82
高階會員 發表:150 回覆:272 積分:189 註冊:2004-03-16 發送簡訊給我 |
|
cobraliu
中階會員 發表:15 回覆:75 積分:83 註冊:2007-11-22 發送簡訊給我 |
拉了兩個edit1,edit2跟一個button 在button中寫了這一段不知這是不是有符合你的需求 case strtoint(edit1.Text) of
1..10: edit2.Text := inttostr(5); 11..20: edit2.Text := inttostr(10); 21..40: edit2.Text := inttostr(20); ELSE IF strtoint(edit1.Text) > 40 THEN edit2.Text := inttostr(40); END;
------
初學、初學、學了很久...還是在初學階段..Orz |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
我的建議: 試著把它寫成函式, 如何?
讓數值的得取動作與結果的顯示分開... ===================引 用 cobraliu 文 章=================== 拉了兩個edit1,edit2跟一個button 在button中寫了這一段不知這是不是有符合你的需求 case strtoint(edit1.Text) of 1..10: edit2.Text := inttostr(5); 11..20: edit2.Text := inttostr(10); 21..40: edit2.Text := inttostr(20); ELSE IF strtoint(edit1.Text) > 40 THEN edit2.Text := inttostr(40); END;
編輯記錄
jow 重新編輯於 2007-12-07 12:30:00, 註解 無‧
|
zhouying82
高階會員 發表:150 回覆:272 積分:189 註冊:2004-03-16 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
記得要處理未定義的輸入範圍....
[code delphi] function TForm1.GetValue0(V: Integer; var ret: Integer): Boolean; begin if V < 1 then ret := -1 else if V <= 10 then ret := 5 else if V <= 20 then ret := 10 else if V <= 40 then ret := 20 else ret := 40; Result := ret <> -1; end; function TForm1.GetValue1(V: Integer; var ret: Integer): Boolean; begin ret := -1; case V of 01..10: ret := 5; 11..20: ret := 10; 21..40: ret := 20; else if V > 40 then ret := 40; end; Result := ret <> -1; end; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin Edit1.Text := '範圍未定義!'; Edit2.Text := '範圍未定義!'; if GetValue0(Random(50), I) then Edit1.Text := IntToStr(I); if GetValue1(Random(50), I) then Edit2.Text := IntToStr(I); end; [/code] ===================引 用 zhouying82 文 章=================== jow,你是否可以提供相关的源码?
編輯記錄
jow 重新編輯於 2007-12-10 00:39:21, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |