ini文件保存用户对控件样式所做的更改(个性化定制)

ini文件保存用户对控件样式所做的更改(个性化定制):

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, PropFilerEh, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh, Data.DB, Data.Win.ADODB, GridsEh, DBAxisGridsEh, DBGridEh, PropStorageEh, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    PropStorageEh1: TPropStorageEh;
    DBGridEh1: TDBGridEh;
    ADOQuery1: TADOQuery;
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    IniPropStorageManEh1: TIniPropStorageManEh;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
  mypath:STRING;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  PropStorageEh1.SaveProperties;//保存用戶對DBGridEh1.<P>.Columns、DBGridEh1.<P>.OptionsEh的屬性所作的改變
  ADOQUERY1.CLOSE;

end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  //Application.ExeName的值為'D:\Ashley\TEST\Win32\Debug\Project1.exe'
  mypath:=ExtractFilePath(Application.ExeName); //mypath的值為'D:\Ashley\TEST\Win32\Debug\'
  ADOQUERY1.Open;
  PropStorageEh1.StorageManager:=IniPropStorageManEh1;
  IniPropStorageManEh1.IniFileName:=mypath+'hahahaha.ini';//ini文檔命名並創建
  //以下2句作用:用戶對控件DBGridEh1做了改動時,保存對象的Columns、OptionsEh與旗下的屬性。
  PropStorageEh1.STOREDPROPS.ADD('DBGridEh1.<P>.Columns');
  PropStorageEh1.StoredProps.ADD('DBGridEh1.<P>.OptionsEh');
  PropStorageEh1.LoadProperties; //加載屬性(若上次有改動則展現的是上次改動過後的樣式)
end;

end.

 

posted @ 2021-09-03 14:57  枭二熊  阅读(96)  评论(0编辑  收藏  举报