首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

以下的语句是什么语法?解决方案

2012-02-27 
以下的语句是什么语法?表达什么意思?propertyreadwrite怎样用法的property mGhNo: String read vGhNo writ

以下的语句是什么语法?
表达什么意思? property read write怎样用法的 
property mGhNo: String read vGhNo write vGhNo;
property mbillNo: String read vbillNo;

[解决办法]
property mGhNo: String read vGhNo write vGhNo;
外部访问该类实例时,是访问的mGhNo,而mGhNo的值取自(更改)内部的vGhNo
property mbillNo: String read vbillNo;
这个同上,但是mbillNo为只读属性,外部不能对他赋值
[解决办法]
property 是delphi的保留字,它定義Delphi類中的屬性
語法:
property 属性名称 read 成员变量或函数 write 成员变量或函数 default 常量
当你以读的方式访问类中的属性时(取值),它实际调用read后面的变量或函数
当你以写的方式访问类中的属性时(赋值),它实际调用write后面的变量或函数
缺省的值为default后面的常量
如:
type t=class
private
x:integer;
function getx:integer;
procedure setx(y:integer);
published
property m_x:integer read getx write setx default 0;
end;

function t.getx:integer;
begin
result:=x;
end;

procedure t.setx(y:integer);
begin
x:=y;
end;


var
t1:t;
i:integer;
begin
t1:=t.Create;
i:=t1.m_x; //调用t.getx,结果为default 0
t1.m_x:=10; //调用t.setx(10)
end;



[解决办法]
property mGhNo: String read vGhNo write vGhNo;
就是说当程序读取mGhNo的值时就从vGhNo中读取,当程序给mGhNo赋值时就把值赋给vGhNo;
read 和write也可以用方法,此时其中read后应为无参数的返回类型与属性类型一致的函数方法名称,write后为带一个参数Value,类型与属性类型一致的过程方法名称

function GetScaled:Boolean;
procedure SetScaled(Value:Boolean);
property Scale:Boolean read GetScaled write SetScaled;

热点排行