Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
技术板块灌水区
» 修改只读属性?
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: 修改只读属性?
kendling
(小冬)
高级版主
MyvNet
UID 703
Digest Posts
5
Credits 978
Posts 580
点点分 978
Reading Access 101
Registered 2005-2-18
Location 广东
Status Offline
#1
Post at 2007-1-24 10:39
Profile
|
Site
|
Blog
|
P.M.
|
|
修改只读属性?
哈,最近发现一个修改只读属性的方法,就是通过指针。
不过还有条件
只能修改变量属性,如:
property ReadOnlyProperty: string
read FReadOnlyProperty
;
如果是方法属性则不能修改:
property ReadOnlyByFunc: string
read GetReadOnlyByFunc
;
例:
TMyClass = class
FProA: string;
public
property ProA: string read FProA;
end;
var
pp: ^string; //定义指针
begin
PP := @TestClass.ProA; //TestClass 是 TMyClass的实例
pp^ := 'This readonly property was modified!';
end;
其他类型的属性也可以噢。
[
本帖最后由 kendling 于 2007-1-24 11:02 编辑
]
小冬
http://MyvNet.com
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#2
Post at 2007-1-24 11:21
Profile
|
Blog
|
P.M.
好点子,加精。
bahamut8348
灌水司司长
UID 4743
Digest Posts
14
Credits 337
Posts 79
点点分 337
Reading Access 10
Registered 2007-1-18
Status Offline
#3
Post at 2007-1-24 11:29
Profile
|
Blog
|
P.M.
极度BS冬仔的头像,
竟然玩起RY来了
做人要厚道,看帖要回贴
skyjacker
版主
茶农
UID 2239
Digest Posts
9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
#4
Post at 2007-1-24 16:17
Profile
|
Blog
|
P.M.
|
顶。
小指针,大作用。
var
I: Integer;
S: string;
I 在内存中是个指针,指向存储变量内容的地址
S 在内存中是个指针的指针,存放指向S内容的指针的地址
指针既是地址。
如果可以获得了具体的内存地址,就可以修改了。
一壶清茶煮青春.
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#5
Post at 2007-1-24 17:07
Profile
|
Blog
|
P.M.
SkyJacker这样说的指针比平常的指针概念多了一层,应该不太符合日常的理解。
C/Pascal等高级语言里头的指针其实是一个存储了地址的内存单元,其存储的内容(是一个地址)所指的地方才是这个指针所指的内容。
而I:Integer只是一个内存单元,I的内容是整型变量,没有地址的说法。
@I才能得到I的地址。
bahamut8348
灌水司司长
UID 4743
Digest Posts
14
Credits 337
Posts 79
点点分 337
Reading Access 10
Registered 2007-1-18
Status Offline
#6
Post at 2007-1-25 12:23
Profile
|
Blog
|
P.M.
左值和右值
做人要厚道,看帖要回贴
koalaone
新警察
UID 4832
Digest Posts 0
Credits 17
Posts 4
点点分 17
Reading Access 10
Registered 2007-1-21
Status Offline
#7
Post at 2007-1-26 14:39
Profile
|
Blog
|
P.M.
有点意思
skyjacker
版主
茶农
UID 2239
Digest Posts
9
Credits 617
Posts 269
点点分 617
Reading Access 100
Registered 2006-6-8
Status Offline
#8
Post at 2007-3-23 08:52
Profile
|
Blog
|
P.M.
|
能不能修改全局常量的值?
用 P := @ConstA 获取指针不能编译.
我想将修改 ConstA 用于
Format(ConstA ,);
如果 ConstA 可以内部修改, 因此可以少不少 If 判断.
[
本帖最后由 skyjacker 于 2007-3-23 08:57 编辑
]
一壶清茶煮青春.
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#9
Post at 2007-3-23 09:03
Profile
|
Blog
|
P.M.
那还用啥const,直接var了。
kendling
(小冬)
高级版主
MyvNet
UID 703
Digest Posts
5
Credits 978
Posts 580
点点分 978
Reading Access 101
Registered 2005-2-18
Location 广东
Status Offline
#10
Post at 2007-3-28 11:59
Profile
|
Site
|
Blog
|
P.M.
|
|
哈哈,对,用var就好了。
小冬
http://MyvNet.com
Poll
Trade
Reward
Activity
CnPack Forum
CnPack English Forum
> CnWizards IDE Wizards
> CVSTracNT
> Announcements & Others
All times are GMT++8, the time now is 2024-11-22 07:13
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.015812 second(s), 7 queries , Gzip enabled
TOP
Clear Cookies
-
Contact Us
-
CnPack Website
-
Archiver
-
WAP
Member's CP Home
Edit Profile
Credits Transaction
Public User Groups
Buddy List
Main
Page Views
User Agents
Posts History
Top Forums
Top Threads
Post Ranking
Credit Ranking
Online Time
Team
Moderation Stats