如何動態產生每個元件的事件 |
答題得分者是:fatmoon1
|
itsgero2798
一般會員 發表:17 回覆:17 積分:6 註冊:2007-09-28 發送簡訊給我 |
|
fatmoon1
初階會員 發表:3 回覆:29 積分:36 註冊:2004-05-24 發送簡訊給我 |
|
pceyes
尊榮會員 發表:70 回覆:657 積分:1140 註冊:2003-03-13 發送簡訊給我 |
ScrollBox1.Width := form1.ClientWidth-frameWidth; ScrollBox1.Height:= form1.ClientHeight-frameheight; ScrollBox1.Top := (form1.ClientHeight- ScrollBox1.Height) div 2; ScrollBox1.Left := (form1.clientwidth-ScrollBox1.Width) div 2; param_ls := tstringlist.Create; cmd_ls := tstringlist.Create; Data_Ls := tstringlist.Create; Str_Ls := tstringlist.Create; try Str_Ls.LoadFromFile(extractfilepath(application.ExeName) 'cmdmenu.txt'); except exit; end; arr_cnt := Str_Ls.count; setlength(Panels,arr_cnt); setlength(Buttons,arr_cnt); setlength(Label1s,arr_cnt); setlength(Label2s,arr_cnt); setlength(Image1s,arr_cnt); for i:=Low(Panels) to High(Panels) do begin Data_Ls.Clear; if Splite_Str(Str_Ls[i])<> 3 then begin exit; end; Label1s[i]:= Tlabel.create(self); Label1s[i].Top := 5; Label1s[i].Left :=Panels[i].Left 60; Label1s[i].font.Color := clblue; Label1s[i].Font.Style := [fsBold] ; Label1s[i].Font.Name := '新細明體'; Label1s[i].Font.Size := 14; Label1s[i].caption := Data_ls[0]; Label1s[i].parent :=Panels[i]; Buttons[i] := TButton.Create(self); Buttons[i].Top := (panel_height-button_height) div 2; Buttons[i].height:= button_height; Buttons[i].Width :=button_width; Buttons[i].Left :=ScrollBox1.width-button_width-40; Buttons[i].caption := '執行'; Buttons[i].tag :=i; Buttons[i].OnClick := MyButtonClick; Buttons[i].parent :=Panels[i]; Image1s[i] := TImage.Create(self); Image1s[i].Left := ((Label2s[i].Left-Panels[i].Left)-32) div 2; Image1s[i].Top := (Panels[i].Height-32) div 2 ; Image1s[i].width := 32; Image1s[i].Height := 32; Image1s[i].parent :=Panels[i]; if fileexists(data_ls[2]) then begin try Image1s[i].Picture.Icon.Handle := ExtractIcon(hInstance, PChar(data_ls[2]),0); except exit; end; end; end; mydir := extractfilepath(application.ExeName); wnd := shellexecute(0,'OPEN',pchar(cmd_ls[tag_int]),pchar(param_ls[tag_int]),pchar(mydir),1); if wnd > 32 then begin form1.close; end else begin showmessage('找不到可執行的檔案' cmd_ls[tag_int]); Buttons[tag_int].enabled := true; end; end;
------
努力會更接近成功 |
itsgero2798
一般會員 發表:17 回覆:17 積分:6 註冊:2007-09-28 發送簡訊給我 |
|
danny
版主 發表:100 回覆:522 積分:595 註冊:2002-03-11 發送簡訊給我 |
你指的 "同時" 是指使用 Thread 嗎 ?
觸發元件的事件, 並不會有的元件沒有動作. 但你要在事件中注意存取共用變數(或記憶體)的問題 ===================引 用 itsgero2798 文 章=================== 再請教一下,若只寫一個事件,在 事件中判斷那個元觸發時,若同時有 數十個元件觸發,因同用一個事件 是否會有觸發的元件沒有動作 ===================引 用 fatmoon1 文 章=================== 先寫好50個事件再指定給這50個元件 跟 寫一個事件,在事件中判斷是那個元件觸發動作 都是可以的 當然 寫一個事件,在事件中判斷是那個元件觸發動作 是比較好的做法
------
將問題盡快結案也是一種禮貌! |
itsgero2798
一般會員 發表:17 回覆:17 積分:6 註冊:2007-09-28 發送簡訊給我 |
其時並非同時,但可能會有數十個元件觸發同一個
事件,而每個觸發的時間差約為50ms左右,這樣 會有問題嗎? ===================引 用 danny 文 章=================== 你指的 "同時" 是指使用 Thread 嗎 ? 觸發元件的事件, 並不會有的元件沒有動作. 但你要在事件中注意存取共用變數(或記憶體)的問題 ===================引 用 itsgero2798 文 章=================== 再請教一下,若只寫一個事件,在 事件中判斷那個元觸發時,若同時有 數十個元件觸發,因同用一個事件 是否會有觸發的元件沒有動作 ===================引 用 fatmoon1 文 章=================== 先寫好50個事件再指定給這50個元件 跟 寫一個事件,在事件中判斷是那個元件觸發動作 都是可以的 當然 寫一個事件,在事件中判斷是那個元件觸發動作 是比較好的做法 |
danny
版主 發表:100 回覆:522 積分:595 註冊:2002-03-11 發送簡訊給我 |
如果你的事件跑完, 用不到50ms就沒有問題.
但如果事件會用到50ms以上(Windows 的處理時間會因為當時電腦的狀況而不同), 要注意 "存取共用變數(或記憶體)的問題" 但事件處理的內容是被分隔的或都不相關, 就不用處理這個問題了... ===================引 用 itsgero2798 文 章=================== 其時並非同時,但可能會有數十個元件觸發同一個 事件,而每個觸發的時間差約為50ms左右,這樣 會有問題嗎? ===================引 用 danny 文 章=================== 你指的 "同時" 是指使用 Thread 嗎 ? 觸發元件的事件, 並不會有的元件沒有動作. 但你要在事件中注意存取共用變數(或記憶體)的問題
------
將問題盡快結案也是一種禮貌! |
itsgero2798
一般會員 發表:17 回覆:17 積分:6 註冊:2007-09-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |