如何用指標簡化程式碼或是更好的辦法 |
答題得分者是:taishyang
|
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
我有4個Image 我要各自載入圖檔 不考慮直接貼上程式碼會太大
內容如下 Image1->Picture->LoadFromFile("bmp\\la1.bmp"); Image2->Picture->LoadFromFile("bmp\\la2.bmp"); Image3->Picture->LoadFromFile("bmp\\la3.bmp"); Image4->Picture->LoadFromFile("bmp\\la4.bmp"); 這是4張的作法 還是有辦法合成一張圖 我可以指定他們的來源位置嗎?
------
有問題大家多討論 大家共同一起進步 |
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
------
有問題大家多討論 大家共同一起進步 |
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
enum { la1bmp, la2bmp, la3bmp, la4bmp, maxpic, } for(i=0;i Imagename->Picture->LoadFromFile("bmp\\bmpname.bmp"); } 就指標想要指向兩件事一個是某個物件 一個是某張圖 不知道如何下手 ===================引 用 kkk730819 文 章=================== 我有4個Image 我要各自載入圖檔 不考慮直接貼上程式碼會太大 內容如下 Image1->Picture->LoadFromFile("bmp\\la1.bmp"); Image2->Picture->LoadFromFile("bmp\\la2.bmp"); Image3->Picture->LoadFromFile("bmp\\la3.bmp"); Image4->Picture->LoadFromFile("bmp\\la4.bmp"); 這是4張的作法 還是有辦法合成一張圖 我可以指定他們的來源位置嗎?
------
有問題大家多討論 大家共同一起進步 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
===================引 用 taishyang 文 章=================== 搜尋一下[FindComponent]的用法 ^^ ====================================== ok ok 3q for(int i=1; i<5; i )//從1開始到4 { ((TImage*)FindComponent("Image" IntToStr(i)))-> //Image1 Image2 Image3 Image4 Picture->LoadFromFile("la" IntToStr(i 1) ".bmp");// la1.bmp la2.bmp la3.bmp la4.bmp } //IntToStr(i) 把變數是整數 轉成 字串
------
有問題大家多討論 大家共同一起進步
編輯記錄
kkk730819 重新編輯於 2010-06-02 15:14:30, 註解 無‧
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
Hello~
請問一下,如果已有五個元件為aaa1,aaa2,aaa3,aaa4,aa5,但 aaa1為TButton, aaa2為TLabel, aaa3為TBitBtn, aaa4為TListBox, aaa5為TEdit, 且這五個元件位於另外一個表單,Form2上, 那這樣FindComponent要怎麼寫呢?3q3q. for(int i=1;i<5;i ) { ((TImage*)FindComponent("aaa" (String)(i)))->Hint="test"; }
編輯記錄
renard 重新編輯於 2010-06-14 12:12:43, 註解 無‧
|
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
(TImage*) 是針對圖片
FindComponent這是針對你有相同的物件 檔名為連續或相似的地方使用 你五個五件都不一樣 我是有看到相關文章 不過忘記在那看的 好像萬用物件...之類搜尋一下罷 不然就發新文章發問罷 ===================引 用 renard 文 章=================== Hello~ 請問一下,如果已有五個元件為aaa1,aaa2,aaa3,aaa4,aa5,但 aaa1為TButton, aaa2為TLabel, aaa3為TBitBtn, aaa4為TListBox, aaa5為TEdit, 且這五個元件位於另外一個表單,Form2上, 那這樣FindComponent要怎麼寫呢?3q3q. for(int i=1;i<5;i ) { ((TImage*)FindComponent("aaa" (String)(i)))->Hint="test"; }
------
有問題大家多討論 大家共同一起進步 |
senso
高階會員 發表:5 回覆:126 積分:226 註冊:2003-11-27 發送簡訊給我 |
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
我所要問題其實算是一種多國語系的問題,
ex: 在Form1設定此程的語言為中文,然後改變Form2的元件Captoin. ((TLabel*) Form1->FindComponent("A1"))->Caption="中文 ((TButton*)Form2->FindComponent("A2"))->Caption="中文"; ((TBitBtn*)Form2->FindComponent("A3"))->Caption="中文"; 我只知道Form有三個元件,A1,A2,A3, 但是我不知到那三個元件是Label,Button or BitBtn. 所以不知道要用TLabel還是TButton. 我總不能針對每個元件,去猜它是什麼型態吧,不知道您有沒有什麼高見呢? for(int i=0;i < Form2->ControlCount; i ) { String name=Form2->Controls[i]->Name; if(name=="A1") { if(Form2->Components[i]-> ((TLabel*)Form2->FindComponent("A1"))->Caption="中文"; } if(Form2->Components[i]->((TButton*)Form2->FindComponent("A1"))->Caption="中文"; } if(Form2->Components[i]-> ((TBitBtn*)Form2->FindComponent("A1"))->Caption="中文"; } } else if(name=="A2") { ;//族繁不及備載 } else if(name=="A3") { ;//族繁不及備載 } } P.S.程式碼無法照板規post上,尚請見諒. |
kkk730819
一般會員 發表:4 回覆:14 積分:8 註冊:2010-05-25 發送簡訊給我 |
這樣物件一多 迴圈也太大罷
去爬文罷 各別去判斷是否有Label,Button,BitBtn物件是否存在...有就改Caption 內容 ===================引 用 renard 文 章=================== 3q3q,果然是行家, 我所要問題其實算是一種多國語系的問題, ex: 在Form1設定此程的語言為中文,然後改變Form2的元件Captoin. ((TLabel*) Form1->FindComponent("A1"))->Caption="中文 ((TButton*)Form2->FindComponent("A2"))->Caption="中文"; ((TBitBtn*)Form2->FindComponent("A3"))->Caption="中文"; 我只知道Form有三個元件,A1,A2,A3, 但是我不知到那三個元件是Label,Button or BitBtn. 所以不知道要用TLabel還是TButton. 我總不能針對每個元件,去猜它是什麼型態吧,不知道您有沒有什麼高見呢? 3q3q,果然是行家, 我所要問題其實算是一種多國語系的問題, ex: 在Form1設定此程的語言為中文,然後改變Form2的元件Captoin. ((TLabel*) Form1->FindComponent("A1"))->Caption="中文 ((TButton*)Form2->FindComponent("A2"))->Caption="中文"; ((TBitBtn*)Form2->FindComponent("A3"))->Caption="中文"; 我只知道Form有三個元件,A1,A2,A3, 但是我不知到那三個元件是Label,Button or BitBtn. 所以不知道要用TLabel還是TButton. 我總不能針對每個元件,去猜它是什麼型態吧,不知道您有沒有什麼高見呢? for(int i=0;i < Form2->ControlCount; i ) { String name=Form2->Controls[i]->Name; if(name=="A1") { if(Form2->Components[i]-> ((TLabel*)Form2->FindComponent("A1"))->Caption="中文"; } if(Form2->Components[i]->((TButton*)Form2->FindComponent("A1"))->Caption="中文"; } if(Form2->Components[i]-> ((TBitBtn*)Form2->FindComponent("A1"))->Caption="中文"; } } else if(name=="A2") { ;//族繁不及備載 } else if(name=="A3") { ;//族繁不及備載 } } P.S.程式碼無法照板規post上,尚請見諒.
------
有問題大家多討論 大家共同一起進步 |
senso
高階會員 發表:5 回覆:126 積分:226 註冊:2003-11-27 發送簡訊給我 |
參考
http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=51576#2 http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=42844#5 TComponent *com=Form1->FindComponent("Button1"); if (GetPropInfo(com->ClassType(),"Caption")) //表示有Caption這個property { SetPropValue(com,"Caption","test"); //Caption="test" }
編輯記錄
senso 重新編輯於 2010-06-14 18:08:56, 註解 無‧
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
|
senso
高階會員 發表:5 回覆:126 積分:226 註冊:2003-11-27 發送簡訊給我 |
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
不好意思,再求教一下,
如果有10個Form,上面都有一個Button1, 用下面的語法,請問要如何修改呢? for(int i=1; i <= 10 ;i ) { StringF1="Form" (String)i; TComponent *com=Form1->FindComponent("Button1"); if (GetPropInfo(com->ClassType(),"Caption")) { SetPropValue(com,"Caption","test"); //Caption="test" } } |
senso
高階會員 發表:5 回覆:126 積分:226 註冊:2003-11-27 發送簡訊給我 |
|
renard
一般會員 發表:3 回覆:43 積分:24 註冊:2007-06-29 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |