線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4998
推到 Plurk!
推到 Facebook!

const 在不同DELPHI版本下的问题

答題得分者是:Coffee
leonli80
一般會員


發表:29
回覆:27
積分:11
註冊:2006-08-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-04-09 23:23:29 IP:222.64.xxx.xxx 訂閱
<textarea class="delphi" rows="10" cols="60" name="code"> const i : integer = 1; //================== 在程式中寫下面的語句 i := 3; </textarea> 如果在Delphi4中,可以編譯成功。 在Delphi7中報錯“Left side cannot be assigned to ” 如何解決?
channel
尊榮會員


發表:67
回覆:707
積分:854
註冊:2002-05-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-04-09 23:49:39 IP:59.114.xxx.xxx 訂閱
小弟用delphi5測試好像沒有問題
是不是delphi7比較嚴謹…
如果是在procedure test(const i: Integer = 1);基本上i是無法再修改的吧…

~小弟淺見,參考看看~
===================引 用 文 章===================
<textarea class="delphi" rows="10" cols="60" name="code">const i : integer = 1; //================== 在程式中寫下面的語句 i := 3; </textarea> 如果在Delphi4中,可以編譯成功。 在Delphi7中報錯“Left side cannot be assigned to ” 如何解決?
------
~小弟淺見,參考看看~
Coffee
版主


發表:31
回覆:878
積分:561
註冊:2006-11-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-04-10 00:01:08 IP:211.74.xxx.xxx 訂閱
check help yourself.

typed constants, unlike true constants, can hold values of array, record, procedural, and pointer types. Typed constants cannot occur in constant expressions.
In the default {$J-} compiler state, typed constants can not have new values assigned to them; they are, in effect, read-only variables. However, if the {$J } compiler directive is in effect, typed constants can have new values assigned to them; they behave essentially like initialized variables.
Declare a typed constant like this:

const identifier: type = value

where identifier is any valid identifier, type is any type except files and variants, and value is an expression of type type. For example,

const Max: Integer = 100;

In most cases, value must be a constant expression; but if type is an array, record, procedural, or pointer type, special rules apply.
------
不論是否我發的文,在能力範圍皆很樂意為大家回答問題。
為了補我的能力不足之處,以及讓答案可以被重複的使用,希望大家能儘量以公開的方式問問題。
在引述到我的文時自然會儘量替各位想辦法,謝謝大家!
harpist
資深會員


發表:3
回覆:251
積分:430
註冊:2002-10-03

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-04-10 00:21:29 IP:59.104.xxx.xxx 未訂閱
既要宣告為"常數"又要改變它的值不是很矛盾嗎?
------
~§~迷時師渡,悟了自渡~§~
Coffee
版主


發表:31
回覆:878
積分:561
註冊:2006-11-15

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-04-10 00:23:32 IP:211.74.xxx.xxx 訂閱
其實我也不算是有真的用過這樣的方式..不過Delphi可以這樣玩應該是錯不了..:P
------
不論是否我發的文,在能力範圍皆很樂意為大家回答問題。
為了補我的能力不足之處,以及讓答案可以被重複的使用,希望大家能儘量以公開的方式問問題。
在引述到我的文時自然會儘量替各位想辦法,謝謝大家!
h@visli
資深會員


發表:103
回覆:429
積分:431
註冊:2004-02-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-04-20 09:22:12 IP:218.18.xxx.xxx 未訂閱
------
------------------------
博采眾家之長,奉獻綿薄之力
------------------------
yufeiying
一般會員


發表:0
回覆:6
積分:1
註冊:2004-06-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-05-05 19:01:34 IP:58.48.xxx.xxx 訂閱
楼主可用编译指令来操作

{$J }
const
I: Integer = 0;
{$J-}
begin
Inc(I);
....
end;
系統時間:2024-04-27 3:08:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!