delphi – 如何自动生成getter和setter方法
我是
Java开发人员,我总是使用getter-setter方法.我怎样才能在Delphi中使用这个概念?
>我定义了一个局部变量// 1 对于这个例子: unit Unit1; type ClassePippo=class private colorText:string; //1 function getColorText: String; //3 procedure setColorText(const Value: String); //3 public property colore: String read getColorText write setColorText; //2 end; implementation { ClassePippo } function ClassePippo.getColorText: String; //3 begin Result:=colorText; end; procedure ClassePippo.setColorText(const Value: String); //3 begin colorText:=Value; end; end. 是否有自动创建getter和setter方法的功能? 我只想写colorText:string; // 1并调用快捷方式,我希望IDE自动创建// 2和// 3. (当我使用Eclipse在Java中开发时,我可以使用Source自动生成getter和setter方法 – >生成getter和setter ……) 解决方法
首先输入您想要的属性而不是内部变量.只需在类中创建以下类型即可
Property Colore:String Read GetColorText Write SetColorText; 然后按Ctrl Shift C. 然后,IDE将创建getter,setter和private内部变量. 请注意,Property Paster中的Property setter和getter是可选的.你可以轻松写 Property Colore:String Read FColorText Write FColorText; 或只有一个二传手或吸气剂 Property Colore:String读取FColorText写入SetColorText; 在这种情况下,IDE将生成私有FColorText变量和setter方法SetColorText (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |