vcl-154042-expresscrossplatformlibrary-how-to-example-tcxpropertiesstore-storeto.md
The following example demonstrates how to use the TcxPropertiesStore component. Consider storing the Color property value of the cxStyle object. This object ( cxTabStyle ) is assigned to the RootLevelStyles.Tab property of a cxGrid control.
The TcxPropertiesStore component does not allow you to save/restore sub-properties of the properties referring to TComponent descendants. So, saving the Color property of a cxStyle object needs a special approach. The following code shows the correct method of saving the Color property of the cxTabStyle style:
//...
//setting the level tabs painting style to cxTabStyle
cxGrid1.RootLevelStyles.Tab := cxTabStyle;
with cxPropertiesStore1 do
begin
//adding a reference to the cxGrid1 control into the Components collection
with TcxPropertiesStoreComponent(Components.Add) do
begin
Component := cxGrid1;
//specifying the
Properties.Add('RootLevelStyles.Tab');
end;
//adding a reference to cxTabStyle into the Components collection
with TcxPropertiesStoreComponent(Components.Add) do
begin
Component := cxTabStyle;
//specifying the Color property for storing/restoring
Properties.Add('Color');
end;
//setting the storage type to INI file
StorageType := stIniFile;
//specifying the name of the INI file
StorageName := 'c:\store.ini';
//saving information
StoreTo;
end;
//...
//...
//setting the level tabs painting style to cxTabStyle
cxGrid1->RootLevelStyles->Tab = cxTabStyle;
TcxPropertiesStoreComponent * APSComponent;
//adding a reference to the cxGrid1 control into the Components collection
APSComponent = (TcxPropertiesStoreComponent *)cxPropertiesStore1->Components->Add();
APSComponent->Component = cxGrid1;
//specifying the
APSComponent->Properties->Add("RootLevelStyles.Tab");
//adding a reference to cxTabStyle into the Components collection
APSComponent = (TcxPropertiesStoreComponent *)cxPropertiesStore1->Components->Add();
APSComponent->Component = cxTabStyle;
//specifying the Color property for storing/restoring
APSComponent->Properties->Add("Color");
//setting the storage type to INI file
cxPropertiesStore1->StorageType = stIniFile;
//specifying the name of the INI file
cxPropertiesStore1->StorageName = "c:\\store.ini";
//saving information
cxPropertiesStore1->StoreTo();
//...
The result of this code execution is shown below:
[cxGrid1: TcxPropertiesStoreComponent]
=
RootLevelStyles.Tab=cxTabStyle
[cxTabStyle: TcxPropertiesStoreComponent]
=
Color=15451300
The resulting file contains all the required information – the RootLevelStyles.Tab style object and the Color property value for that object.