English 中文(简体)
如何创造只读的财产?
原标题:How to create a read-only property?
  • 时间:2011-04-21 02:45:36
  •  标签:
  • delphi

我正在使用一个TMS物体监察员,但假定我的问题在设计时间对Delphi同样有效。

我想有一个能够按方案(在时间)或硬编码(在设计时间)确定的财产。 用户应当看到这一信息,因为信息对他有用,因此,信息在方案操作时间上应当改变,但用户不应通过目标检查员改变。

审判

published property FileName : String read FFileName;

并且财产是显而易见的,但物品检查员也可以改变(如果改变,将读出地址为零0除外)

最佳回答

这看起来是完全有效和正确的<>只有。 财产

published property FileName : String read FFileName;

如果你增加公共财产,因此在经营期间只能确定:

public property RuntimeFilename: string read FFileName write FFilename;
//note that two properties, one published and one public point to the same field.

However if you want to hack it and get rid of the exception in Design-time
change it to:

//Only writable during runtime.
private
  procedure SetFileName(Value: string);
published
  property FileName: string read FFileName write SetFileName;

....
procedure TMyClass.SetFileName(Value: string);
begin
  if csDesigning in Componentstate then {do nothing}
  else FFileName:= Value;
end;

www.un.org/Depts/DGACM/index_spanish.htm 我认为也可以做些什么。

Disconnect between designtime and runtime code
In order to change the runtime behaviour of the code you need only change the source code and remove the write ... part of the property.

This will not effect the design-time code though, for that you need to reinstall the component.
If you change the source code of a registered component and you keep the changes within the private, protected and/or public sections of the component you are usually OK.

但是,如果您修改了一部分内容的<代码>公布的<>>>,并且你不会再重复这一组成部分,你在开始时会有不正常的行为。

这是因为在设计时间上,你仍在使用该构成部分的老版/译本。 该版本的没有write/code>部分被删除<>/strong>,并允许您修改其背后示意图

Come runtime the init-code will read the form resource 1) and spots a value to be written to FFilename. However the procedure SetFilename is no longer available and therefore a access violation occurs during program startup.

1 (现存放在您的的散射资源内的数据)。

问题回答

最容易的方式:

private
  procedure SetFileName(Value: string);
published
  property FileName: string read FFileName write SetFileName;

....
procedure TMyClass.SetFileName(Value: string);
begin
  FFileName := FFileName;
end;

这显然是泰米尔猛虎人解组织目标检查员的ug子,你应向猛虎人解组织提交一份丑闻。





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...