全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1169
推到 Plurk!
推到 Facebook!

字元 (string) 的『 += 』用法

答題得分者是:gemi0305
koya
一般會員


發表:2
回覆:0
積分:0
註冊:2003-08-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-21 09:13:41 IP:163.28.xxx.xxx 未訂閱
◆操作環境為 bcb 6 ◆所用元件為 from 、 memo 及 button ◆button的程式碼如下:    char buffer[]="a"; Memo1->Text = "---12345---"; Memo1->Text = Memo1->Text 十 buffer;         //==>在Memo1上可看到『---12345---a』 //Memo1->Text 十= buffer;                 //==>在Memo1上可看到『---12345---』    ◆我的問題是: 為何『Memo1->Text = Memo1->Text 十 buffer;』與『Memo1->Text 十= buffer;』所陳現的結果不同?(其原因為何?我查了memo下的text及AnsiString的help,而AnsiString亦有提供「十=」的運算元,仍不知原因。)是bcb 6本身的問題?還是另有原因?或是 十= 的用法錯誤? ◆備注:「加( )」這個字無法在網頁-預視中使用,所以用「十」取代 發表人 - koya 於 2003/08/21 09:39:04
gemi0305
版主


發表:81
回覆:564
積分:629
註冊:2003-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-21 10:04:49 IP:210.66.xxx.xxx 未訂閱
你好, 用 BCB Online Help 查 "+=" 可以到資料,    其中最底行寫著:    Note:        There are certain conditions where assignment operators are not supported when used with properties.    properities 中又寫: When working with data members of a class which have been declared as properties, certain assignment operators are not supported.  For example, an Edit Box's Text property is not a actually variable, but is, in fact, a pair of function calls that set an internal class variable (SetText(t)) and return its value (GetText()) by value.    Case 1    Edit1->Text = Edit1->Text + "foo";    Case 2    Edit1->Text += "foo";    Case 1, which is in the form of a = a + b, generates code looks like this:    SetText(GetText() + "foo");    which is fine and yields the expected results.     Case 2, which is in the form of a+=b, generates code looks like this:    temp = GetText(); temp += "foo";    which does not work as expected, as the temporary variable is the one being operated on and the setter for the Text property of the Edit control is never called.    從case 2 就知道為什麼不能了  國泰平安
系統時間:2024-06-29 6:03:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!