Some experience in learning Delphi, write it here, for your reference, if there is any mistakes or wrong, I hope to advise.
People who use C know that there is static attributes and static methods in C classes, bringing more convenience to program design. So how is the static attributes and static methods in Delphi? Please see the following example:
Unit unit2;
Interface
TYPE TMYCLASS = Class Public {Static Process: Sets the value of static properties} Class Procedure setStaticMeMberValue (String); {Static function: Read the value of static properties} Class Function GetStaticMevalue: string;
Implementation {This declares static properties, this point is very different from C } var AstaticMember: string;
Class Function TMYCLASS.GETSTATICMEMBERVALUE: String; Begin Result: = astaticmember;
Class Procedure Tmyclass.SetStaticMemberValue (astring: string); begin astaticmember: = astring;
End.
So whether the properties and methods declared in TMYCLASS are static attributes or static methods? Please see the example below:
... USES Unit2 ...
procedure TForm1.Button2Click (Sender: TObject); begin {statement without TMyClass instance can be directly read and set the value of the static attribute} TMyClass.SetStaticMemberValue ( 'MyClass'); showmessage (TMyClass.GetStaticMemberValue); end;