Interface can be configured to read and write configuration files, VCL provides a way to save the interface resources TReader and Twriter way.
Object Form1:tform1 Left = 0 Top = 0 Caption = ' Form1 ' ...
Object Lbl1:tlabel Left = Top = 152
... End Object Btn1:tbutton Left = 184 ...
EndEnd
directly into the text format resource file, as long as the object inherits from the Tpersistent all attribute fields can be initialized normally. At the same time, his inner child objects are persisted by nesting.
Based on this relatively simple storage scheme of nested patterns.
1. The process of reading the configuration and generating the interface
- Load the property information for itself first
- When you load the configuration information for a submodule
- Trigger Interface Initialization Load Event
Through the above three steps to achieve similar Delphi interface configuration information read. Consider the storage location and manner of the specific configuration file format to be implemented by the framework so that it interfaces
Iviewstore implements the basic way to read and write property values.
The iviewstoreattributs interface is not required and can be implemented or not implemented. The purpose of adding this interface is to configure all properties that need to be persisted for the same place. The common genus Tfiler can be understood as publish to obtain the information needed for persistence through RTTI , facilitating access to all relevant information.
1//1 Save properties 2//3///interface need to save and restore property Information 4////To reduce complexity, attribute information should not be nested 5 iviewstoreattributs = Interface 6 [' {e4c17a34-83ac- 4C32-BD18-4C76A9F56D75} '] 7 function Getcount:integer; stdcall; 8 function GetNames (Index:integer): widestring; stdcall; 9 function GetValues (index:integer): widestring; STDCALL;10 procedure Setvalues (index:integer; const value:widestring); Stdcall;11 Property Count:integer Read Getcount;12 property Names[index:integer]: widestring read getnames;13 prop Erty Values[index:integer]: widestring read GetValues write setvalues;14 end;15 16//1 interface Data storage 17///18//For saving interface-specific data information 19 For example, view location Iviewstore = Interface (iinterface) [' {bbc202fa-03d7-4a1f-bb28-13990db87f1e} ']22 procedure Clear; stdcall;23 function Count:integer; STDCALL;24 procedure Erase (const aname:widestring); stdcall;25 function Exists (const aname:widestring): Boolean; stdcall;26 function GetNames (index:integer): widestring; stdcall;27 function Getvalueofindex (Index:Integer): widestring; stdcall;28 function Readbool (const aname:widestring; Default:boolean): Boolean; stdcall;30 function readfloat (const aname:widestring; default:double): Double; stdcall;31 function Readinteger (const aname:widestring; Default:longint): Longint; stdcall;32 function ReadString (const AName, default:widestring): widestring; STDCALL;33 procedure Writebool (const aname:widestring; Value:boolean); STDCALL;34 procedure writefloat (const aname:widestring; value:double); STDCALL;35 procedure Writeinteger (const aname:widestring; Value:longint); STDCALL;36 procedure WriteString (const AName, value:widestring); STDCALL;37 procedure Writeattribs (const attribs:iviewstoreattributs); STDCALL;39 procedure Readattribs (const attribs:iviewstoreattributs); STDCALL;40 procedure Write (const aname:widestring; out Astore:iviewstore); stdcall;41 function Read (const aname:widestring; out Astore:iviewstore): Boolean stdcall;42-Property Names[index: Integer]: widestring read getnames;44 property Valueofindex[index:integer]: widestring read getvalueofindex;45 end;
For module Nesting considerations
1 procedure writeattribs (const attribs:iviewstoreattributs); Stdcall;2 procedure readattribs (const ATTRIBS: Iviewstoreattributs); Stdcall;3 Procedure Write (const aname:widestring; out astore:iviewstore); stdcall;4 function Read (const aname:widestring; Out Astore:iviewstore): Boolean stdcall;
Use the Write and Read functions to get iviewstore so that the external does not consider the specific creation method of the interface instance.
At the same time for some simple objects as long as the implementation of the Iviewstoreattributs interface, in the persistence and initialization of the time not to consider who help you initialize.
Related issues:
If you want to implement fully automatic loading, should the iviewstoreattributs interface be strengthened to achieve the purpose?
Http://www.cnblogs.com/gleam/archive/2012/12/06/2804933.html
Interface Dynamic configuration: Persistent anti-persistence