Everyone can use a class of properties (Property) to use it in Delphi or C #, you can use it to access the private member of the class (of course, the method is controlled),
As follows: public class persourn {private int _age;
Public int Age {get {return _age;} set {if (value> 0) _age = value;}} I have not said that it is said that all kinds of information said than I explained, everyone is also very clear.
Is there such a Dongdong when you create an object in the PB, we ask questions: Does the property exist?
I am looking for, I finally found a good stuff with the help of my friend, it is the Indirect keyword, which can help us achieve attributes in PB (Property
This stuff is.
How to use indirect, let's take a specific action;)
1. Create a class, aunt called UO_PERSON .2. Declare an instance variable private integer _age (instance variable declaration in Declare -> Instance Variables, don't need me to say, here is waste
^ _ ^) 3. Create two object functions: // ================================= ================== 设置 设置 设置 _ --------------------------- ---------------------- // Return: Integer fixed constraint, required to be integer // -------------- ----------------------------------- // Description: Function grammar is not in PB, I am To express it, it is / / =========================================== ====== Private integer of_setage {if AIAGE> 0 THEN _AGE = aIAGE RETURN 1 else Return -1 end if} // ================== ========================================= read _AGE // ----------- ----------------------------------- // Return: Integer type is consistent with the private example field // ======================================================== private integer Of_getage () {return _age} 4. Declaring a special field (equivalent to attribute), the format is as follows: public indirect integer agn {of_setage ()} To this, we belt access to The class is complete.
Write a code test;) UO_PERSON Luo_TEST
Luo_TEST = CREATE UO_PERSON
Luo_TEST.AGE = 25
MessageBox ('Info', 'My Age IS' String (Luo_TEST.AG)) successfully displays my age and is very good.
Such a class is a bit trouble, but it has a lot of benefits. Everyone encounters problems that need such a problem in practical applications. If you want to think about it, he wants me, 嘿嘿;)