Using the DevExpress VCL TdxLayoutControl, how do I store configuration information 1) to multiple databases 2) in an INI file format?

Here is our issue. The TdxLayoutControl can store its configuration in three ways: an INI file, a Windows Registry, or a TStream (which can be used to store a BLOB in the database). The INI file stores the data in a user-consumable format. The Windows Registry and TStream options store the data in a binary format. We (being the daredevils we are) would like to have our cake and eat it too.

We would like to:

  1. Store TdxLayoutControl customization into a database BLOB field.
  2. Store that data in a text-based INI format (or be able to retrieve/manipulate that data in a text-based format).
  3. Be able to specify which database we want to store/retrieve that data from (this is a multi-tenant/multi-database situation with certain applications that span tenants/databases).

Here is what we can seem to do:

  1. I can accomplish points 1 & 3 using StoreToStream.
  • The challenge with this solution is that the data is stored in a binary format
  1. I can accomplish points 1 & 2 using StoreToStorage with custom overridden TcxIniFileReader and TcxIniFileWriter classes that can write to the database instead of a file but can only use a global variable to get the database connection information.
  • The challenge with this solution is that because the container is responsible for instantiating the TcxIniFileReader/Writer descendant, we cannot pass database connection parameters via anything other than the AStorageName parameter – which gets unusable really quickly.

The options that I have thought of (and there likely are other ones) are:

  1. Have a way to specify that the StoreToStream functionality to choose which format to store it in (binary/text INI)
  2. Have a way to pass in an instantiated TcxIniFileReader/Writer descendant into the StoreToStorage method.
  3. Have the TcxIniFileReader/Writer descendant class be able to access the calling TdxLayoutContainer (we are using the tag to store an object with instantiation information).
  4. Have some sort of parsing helper that would allow us to retrieve the binary data stored in the BLOB field, present it in INI format, and then re-parse it for storage back into the BLOB field.

If anyone has any other ideas, I’m game.

Here is the code for my mock-up of a StoreToStream solution (which does not save in an INI text format, but does save in binary).

Test.dpr

program Test;

uses
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Unit1.pas

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
  dxSkinBasic, 
  // DevExpress Skins omitted ...
  dxLayoutcxEditAdapters, cxContainer, cxEdit, dxLayoutContainer, cxTextEdit, Data.DB,
  Data.Win.ADODB, cxClasses, dxLayoutControl, Vcl.Menus, Vcl.StdCtrls, cxButtons, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    lcMainGroup_Root: TdxLayoutGroup;
    lcMain: TdxLayoutControl;
    cxTextEdit1: TcxTextEdit;
    dxLayoutItem1: TdxLayoutItem;
    cxTextEdit2: TcxTextEdit;
    dxLayoutItem2: TdxLayoutItem;
    cxTextEdit3: TcxTextEdit;
    dxLayoutItem3: TdxLayoutItem;
    cxTextEdit4: TcxTextEdit;
    dxLayoutItem4: TdxLayoutItem;
    dxLayoutGroup1: TdxLayoutGroup;
    dxLayoutGroup2: TdxLayoutGroup;
    Panel1: TPanel;
    cxButton1: TcxButton;
    cxButton2: TcxButton;
    procedure FormCreate(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
  private
    FADOConnection: TADOConnection;
    FADOQuery: TADOQuery;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  LayoutName: string = 'TestLayout';

const
  FilterFormat: string = 'Name = ''%s''';

procedure TForm1.cxButton1Click(Sender: TObject);
begin
  lcMain.Customization := True;
end;

procedure TForm1.cxButton2Click(Sender: TObject);
var
  LStream: TMemoryStream;
  LField: TBlobField;
begin
  FADOQuery.Open;
  FADOQuery.Edit;
  LStream := TMemoryStream.Create;
  try
    lcMain.Container.StoreToStream(LStream);
    LField := FADOQuery.FieldByName('DataMemo') as TBlobField;
    LField.LoadFromStream(LStream);
    FADOQuery.Post;
  finally
    FADOQuery.Close;
    LStream.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  LStream: TStream;
  LField: TField;
begin
  FADOConnection := TADOConnection.Create(Self);
  FADOConnection.ConnectionString := 'Provider=SQLOLEDB.1;' + 'Integrated Security=SSPI;' +
    'Persist Security Info=False;' + 'Initial Catalog=Test;' + 'Data Source=localhostSQLEXPRESS';
  FADOQuery := TADOQuery.Create(Self);
  FADOQuery.Connection := FADOConnection;
  FADOQuery.SQL.Add('SELECT * FROM [Layouts] WHERE [Name] = ''TestLayout''');
  FADOQuery.Open;
  try
    if not FADOQuery.FieldByName('DataMemo').IsNull then
    begin
      LField := FADOQuery.FieldByName('DataMemo');
      LStream := FADOQuery.CreateBlobStream(LField, bmRead);
      lcMain.Container.RestoreFromStream(LStream);
    end;
  finally
    FADOQuery.Close;
  end;
end;

end.

Unit1.dfm

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 441
  ClientWidth = 624
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'Segoe UI'
  Font.Style = []
  OnCreate = FormCreate
  TextHeight = 15
  object lcMain: TdxLayoutControl
    Left = 0
    Top = 0
    Width = 624
    Height = 384
    Align = alClient
    TabOrder = 0
    object cxTextEdit1: TcxTextEdit
      Left = 92
      Top = 33
      Style.BorderColor = clWindowFrame
      Style.BorderStyle = ebs3D
      Style.HotTrack = False
      Style.TransparentBorder = False
      TabOrder = 0
      Text = 'cxTextEdit1'
      Width = 121
    end
    object cxTextEdit2: TcxTextEdit
      Left = 92
      Top = 63
      Style.BorderColor = clWindowFrame
      Style.BorderStyle = ebs3D
      Style.HotTrack = False
      Style.TransparentBorder = False
      TabOrder = 1
      Text = 'cxTextEdit2'
      Width = 121
    end
    object cxTextEdit3: TcxTextEdit
      Left = 92
      Top = 128
      Style.BorderColor = clWindowFrame
      Style.BorderStyle = ebs3D
      Style.HotTrack = False
      Style.TransparentBorder = False
      TabOrder = 2
      Text = 'cxTextEdit3'
      Width = 121
    end
    object cxTextEdit4: TcxTextEdit
      Left = 92
      Top = 158
      Style.BorderColor = clWindowFrame
      Style.BorderStyle = ebs3D
      Style.HotTrack = False
      Style.TransparentBorder = False
      TabOrder = 3
      Text = 'cxTextEdit4'
      Width = 121
    end
    object lcMainGroup_Root: TdxLayoutGroup
      AlignHorz = ahLeft
      AlignVert = avTop
      Hidden = True
      ItemIndex = 1
      ShowBorder = False
      Index = -1
    end
    object dxLayoutItem1: TdxLayoutItem
      Parent = dxLayoutGroup1
      CaptionOptions.Text = 'cxTextEdit1'
      Control = cxTextEdit1
      ControlOptions.OriginalHeight = 23
      ControlOptions.OriginalWidth = 121
      ControlOptions.ShowBorder = False
      Index = 0
    end
    object dxLayoutItem2: TdxLayoutItem
      Parent = dxLayoutGroup1
      CaptionOptions.Text = 'cxTextEdit2'
      Control = cxTextEdit2
      ControlOptions.OriginalHeight = 23
      ControlOptions.OriginalWidth = 121
      ControlOptions.ShowBorder = False
      Index = 1
    end
    object dxLayoutItem3: TdxLayoutItem
      Parent = dxLayoutGroup2
      CaptionOptions.Text = 'cxTextEdit3'
      Control = cxTextEdit3
      ControlOptions.OriginalHeight = 23
      ControlOptions.OriginalWidth = 121
      ControlOptions.ShowBorder = False
      Index = 0
    end
    object dxLayoutItem4: TdxLayoutItem
      Parent = dxLayoutGroup2
      CaptionOptions.Text = 'cxTextEdit4'
      Control = cxTextEdit4
      ControlOptions.OriginalHeight = 23
      ControlOptions.OriginalWidth = 121
      ControlOptions.ShowBorder = False
      Index = 1
    end
    object dxLayoutGroup1: TdxLayoutGroup
      Parent = lcMainGroup_Root
      CaptionOptions.Text = 'New Group'
      Index = 0
    end
    object dxLayoutGroup2: TdxLayoutGroup
      Parent = lcMainGroup_Root
      CaptionOptions.Text = 'New Group'
      ItemIndex = 1
      Index = 1
    end
  end
  object Panel1: TPanel
    Left = 0
    Top = 384
    Width = 624
    Height = 57
    Align = alBottom
    Caption = 'Panel1'
    ShowCaption = False
    TabOrder = 1
    object cxButton1: TcxButton
      Left = 16
      Top = 16
      Width = 75
      Height = 25
      Caption = 'Customize'
      TabOrder = 0
      OnClick = cxButton1Click
    end
    object cxButton2: TcxButton
      Left = 488
      Top = 16
      Width = 123
      Height = 25
      Caption = 'Save Customization'
      TabOrder = 1
      OnClick = cxButton2Click
    end
  end
end

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật