关于property.

关于property. 
在Delphi当中,往往将一个类的变量定义在private或者protected里面,这样外部是访问不到这些变量的。当有需要将某个或者某些变量暴露出来给外界访问,就在pulic区或者published区定义一个property。property后面跟着的read表示外界引用这个property的时候,从什么地方返回值,write表示外界给这个property赋值的时候,把这个值放到什么地方去,default对于写控件才有用,表示属性栏里面显示的该属性的缺省值。例如: 

 

Delphi代码
  1. TMyClass   =   Class    
  2. private    
  3.     FField1:   integer;    
  4.     FField2:   string;    
  5.     FField3:   boolean;    
  6.   
  7.     function   GetField3:   boolean;    
  8.     procedure   SetField3(AField:   boolean);    
  9. public    
  10.     property   Field1:   integer   read   FField1   write   FField1;    
  11. published    
  12.     property   Field2:   string   read   FField2;    
  13.     property   Field3:   boolean   read   GetField3   write   SetField3;    
  14. end;    
  15.   
  16. implements    
  17.   
  18. function   TMyClass.GetField3:   boolean;    
  19. begin    
  20.     //注意这里用FField3而不是Field3.    
  21.     result   :=   FField3;    
  22. end;    
  23.   
  24. procedure   TMyClass.SetField3(AField:   boolean);    
  25. begin    
  26.     //注意这里用FField3而不是用Field3,因为Field3是专门供外部使用的。    
  27.     FField3   :=   AField;    
  28. end;    


 

Delphi代码
  1. //现在你可以这样调用了:    
  2. var    
  3.     myClass:   TMyClass;    
  4.     i:   integer;    
  5.     s:   string;    
  6.     b:   boolean;    
  7. begin    
  8.     myClass   :=   TMyClass.Create;    
  9.     try    
  10.         myClass.Field1   :=   1;    
  11.         i   :=   myClass.Field1;    
  12.   
  13.         s   :=   myClass.Field2;    
  14.         myClass.Field2   :=   '这句出错,因为Field2是只读的,没有Write ';    
  15.   
  16.         myClass.Field3   :=   true;   //自动调用TMyClass.SetField3(True)    
  17.         b   :=   myClass.Field3;         //自动调用TMyClass.GetField3返回结果给b    
  18.     finally    
  19.         myClass.Free;    
  20.     end;    
  21. end;  

 

package com.hw.camunda.config.datasource; import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; import com.baomidou.dynamic.datasource.creator.DataSourceCreator; import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; @Configuration public class DynamicDataSourceConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource.dynamic") public DataSource dataSource() { DynamicRoutingDataSource ds = new DynamicRoutingDataSource(); return ds; } @Bean public DataSourceCreator dataSourceCreator() { return new DefaultDataSourceCreator() { @Override public DataSource createDataSource(DataSourceProperty dataSourceProperty) { // 解密username和password if (dataSourceProperty.getUsername() != null && dataSourceProperty.getUsername().startsWith("ENC(")) { String encrypted = dataSourceProperty.getUsername().substring(4, dataSourceProperty.getUsername().length() - 1); dataSourceProperty.setUsername(encrypted); } if (dataSourceProperty.getPassword() != null && dataSourceProperty.getPassword().startsWith("ENC(")) { String encrypted = dataSourceProperty.getPassword().substring(4, dataSourceProperty.getPassword().length() - 1); dataSourceProperty.setPassword(encrypted); } return super.createDataSource(dataSourceProperty); } }; } } 报错使用不了,我要动态的去解密所有的数据库账号和密码
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值