RegUnit.~pa
上传用户:tj00001
上传日期:2007-01-07
资源大小:672k
文件大小:9k
源码类别:

行业应用

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. //(R)CopyRight KivenSoft International ,inc 1999
  3. //单元名称:读写注册表单元
  4. //程序名称:电子书库
  5. //作    者:李会文
  6. //开始时间:1999.07.01
  7. //最后修改:1999.07.06
  8. //备注:此单元定义了读写注册表中应用程序各种信息的单元,在应用程序初始时进行
  9. //---------------------------------------------------------------------------
  10. unit RegUnit;
  11. interface
  12. uses
  13.   IniFiles, SysUtils, Forms, Graphics, MainUnit;
  14. type
  15.   TAppIni=class
  16.   private
  17.     FileName:string;
  18.   public
  19.     //数据库的各类设置
  20.     MyLoveFile                       :string;        //我的最爱数据库名
  21.     NearFile                         :string;        //上次关闭时的数据库名
  22.     FileList                         :array[0..4] of string;//最近打开的5个文件
  23.     OpenSrmWithApp                   :boolean;       //SRM文件是否用应用程序打开
  24.     LoadNearFile                     :boolean;       //运行时是否装入上次打开的数据库
  25.     MyLoveVisible                    :boolean;       //菜单上我的最爱是否显示
  26.     FileListVisible                  :boolean;       //最近打开文件列表是否显示
  27.     SaveDbQuery                      :boolean;       //保存数据库前是否提示
  28.     DelRecordQuery                   :boolean;       //删除记录前是否提示
  29.     //类成员函数
  30.     constructor Create;
  31.     destructor Destroy;override;
  32.   end;
  33. const
  34.   csWidth='Width';
  35.   csHeight='Height';
  36.   csLeft='Left';
  37.   csTop='Top';
  38.   csState='State';
  39.   csVisible='Visible';
  40.   csColor='Color';
  41.   csFontName='FontName';
  42.   csFontSize='FontSize';
  43.   csFontColor='FontColor';
  44.   csFontStyle='FontStyle';
  45.   csReadOnly='Edit';
  46.   csWordWrap='WordWrap';
  47.   csFileSection='File';
  48.   csMyLoveFile='MyLoveFile';
  49.   csNearFile='NearFile';
  50.   csFileList0='FileList0';
  51.   csFileList1='FileList1';
  52.   csFileList2='FileList2';
  53.   csFileList3='FileList3';
  54.   csFileList4='FileList4';
  55.   csOpenSrmWithApp='OpenSrmWithApp';
  56.   csLoadNearFile='LoadNearFile';
  57.   csMyLoveVisible='MyLoveVisible';
  58.   csFileListVisible='FileListVisible';
  59.   csSaveDbQuery='SaveDbQuery';
  60.   csDelRecordQuery='DelRecordQuery';
  61. var
  62.   AppIni:TAppIni;
  63. implementation
  64. constructor TAppIni.Create;
  65. var
  66.   i,n:integer;
  67.   Ini:TIniFile;
  68.   pStyles:pointer;
  69.   s:string;
  70. begin
  71.   //求出应用程序的INI文件名
  72.   FileName:=Application.ExeName;
  73.   n:=Length(FileName);
  74.   FileName[n-2]:='i';
  75.   FileName[n-1]:='n';
  76.   FileName[n]  :='i';
  77.   FileName:=LowerCase(FileName);
  78.   Ini:=TIniFile.Create(FileName);
  79.   with Ini do
  80.   begin
  81.     //MainFrom Section
  82.     with SrmForm do
  83.     begin
  84.       s:=Name;
  85.       SetBounds(ReadInteger(s,csLeft,0),
  86.                 ReadInteger(s,csTop,0),
  87.                 ReadInteger(s,csWidth,Width),
  88.                 ReadInteger(s,csHeight,Height));
  89.       WindowState:=TWindowState(ReadInteger(s,csState,integer(WindowState)));
  90.     end;
  91.     //LeftFrom Section
  92.     with SrmForm.LeftForm do
  93.     begin
  94.       s:=Name;
  95.       Width:=ReadInteger(s,csWidth,Width);
  96.       Visible:=ReadBool(s,csVisible,Visible);
  97.     end;
  98.     //TreeView Section
  99.     with SrmForm.TreeView do
  100.     begin
  101.       s:=Name;
  102.       Color:=ReadInteger(s,csColor,Color);
  103.       with SrmForm.TreeView.Font do
  104.       begin
  105.         Name:=ReadString(s,csFontName,Name);
  106.         Size:=ReadInteger(s,csFontSize,Size);
  107.         Color:=ReadInteger(s,csFontColor,Color);
  108.         n:=ReadInteger(s,csFontStyle,0);
  109.         pStyles:=@n;
  110.         Style:=TFontStyles(pStyles^);
  111.       end;
  112.     end;
  113.     //RichEdit Section
  114.     with SrmForm.RichEdit do
  115.     begin
  116.       s:=Name;
  117.       Color:=ReadInteger(s,csColor,Color);
  118.       with SrmForm.RichEdit.Font do
  119.       begin
  120.         Name:=ReadString(s,csFontName,Name);
  121.         Size:=ReadInteger(s,csFontSize,Size);
  122.         Color:=ReadInteger(s,csFontColor,Color);
  123.         n:=ReadInteger(s,csFontStyle,0);
  124.         pStyles:=@n;
  125.         Style:=TFontStyles(pStyles^);
  126.       end;
  127.       ReadOnly:=ReadBool(s,csReadOnly,ReadOnly);
  128.       WordWrap:=ReadBool(s,csWordWrap,WordWrap);
  129.     end;
  130.     //ToolBar Section
  131.     with SrmForm.ControlBar do
  132.     begin
  133.       s:=Name;
  134.       n:=ControlCount-1;
  135.       for i:=0 to n do
  136.       with SrmForm.ControlBar.Controls[i] do
  137.       begin
  138.         Left:=ReadInteger(s,Name+csLeft,Left);
  139.         Top:=ReadInteger(s,Name+csTop,Top);
  140.       end;
  141.     end;
  142.     //StatusBar Section
  143.     with SrmForm.StatusBar do
  144.     begin
  145.       s:=Name;
  146.       Visible:=ReadBool(s,csVisible,Visible);
  147.     end;
  148.     //ToolBar SpeedButton
  149.     with SrmForm do
  150.     begin
  151.       TitleToolButton.Down:=LeftForm.Visible;
  152.       ReadOnlyToolButton.Down:=RichEdit.ReadOnly;
  153.     end;
  154.     //File Section
  155.     MyLoveFile:=ReadString(csFileSection,csMyLoveFile,'');
  156.     NearFile:=ReadString(csFileSection,csNearFile,'');
  157.     FileList[0]:=ReadString(csFileSection,csFileList0,'');
  158.     FileList[1]:=ReadString(csFileSection,csFileList1,'');
  159.     FileList[2]:=ReadString(csFileSection,csFileList2,'');
  160.     FileList[3]:=ReadString(csFileSection,csFileList3,'');
  161.     FileList[4]:=ReadString(csFileSection,csFileList4,'');
  162.     OpenSrmWithApp:=ReadBool(csFileSection,csOpenSrmWithApp,true);
  163.     LoadNearFile:=ReadBool(csFileSection,csLoadNearFile,true);
  164.     MyLoveVisible:=ReadBool(csFileSection,csMyLoveVisible,true);
  165.     FileListVisible:=ReadBool(csFileSection,csFileListVisible,true);
  166.     SaveDbQuery:=ReadBool(csFileSection,csSaveDbQuery,true);
  167.     DelRecordQuery:=ReadBool(csFileSection,csDelRecordQuery,true);
  168.     //MainMenu
  169.     with SrmForm do
  170.     begin
  171.       StatusMenuItem.Checked:=StatusBar.Visible;
  172.       TitleMenuItem.Checked:=LeftForm.Visible;
  173.       ReadOnlyMenuItem.Checked:=RichEdit.ReadOnly;
  174.     end;
  175.   Ini.Free;
  176.   end;
  177. end;
  178. destructor TAppIni.Destroy;
  179. var
  180.   i,n:integer;
  181.   Ini:TIniFile;
  182.   tmpStyles:TFontStyles;
  183.   pStyles:pointer;
  184.   s:string;
  185. begin
  186.   Ini:=TIniFile.Create(FileName);
  187.   with Ini do
  188.   begin
  189.     //MainFrom Section
  190.     with SrmForm do
  191.     begin
  192.       s:=Name;
  193.       WriteInteger(s,csState,integer(WindowState));
  194.       if WindowState<>wsNormal then
  195.       begin
  196.       WriteInteger(s,csWidth,540) ;
  197.       WriteInteger(s,csHeight,411);
  198.       WriteInteger(s,csLeft,Screen.Height div 2);
  199.       WriteInteger(s,csTop,Screen.Width div 2)
  200.       end
  201.       else
  202.       begin
  203.       WriteInteger(s,csWidth,Width);
  204.       WriteInteger(s,csHeight,Height);
  205.       WriteInteger(s,csLeft,Left);
  206.       WriteInteger(s,csTop,Top);
  207.     end;
  208.     end;
  209.     //LeftFrom Section
  210.     with SrmForm.LeftForm do
  211.     begin
  212.       s:=Name;
  213.       WriteInteger(s,csWidth,Width);
  214.       WriteBool(s,csVisible,Visible);
  215.     end;
  216.     //TreeView Section
  217.     with SrmForm.TreeView do
  218.     begin
  219.       s:=Name;
  220.       WriteInteger(s,csColor,Color);
  221.       with SrmForm.TreeView.Font do
  222.       begin
  223.         WriteString(s,csFontName,Name);
  224.         WriteInteger(s,csFontSize,Size);
  225.         WriteInteger(s,csFontColor,Color);
  226.         tmpStyles:=Style;
  227.         pStyles:=@TmpStyles;
  228.         WriteInteger(s,csFontStyle,integer(pStyles^));
  229.       end;
  230.     end;
  231.     //RichEdit Section
  232.     with SrmForm.RichEdit do
  233.     begin
  234.       s:=Name;
  235.       WriteInteger(s,csColor,Color);
  236.       with SrmForm.RichEdit.Font do
  237.       begin
  238.         WriteString(s,csFontName,Name);
  239.         WriteInteger(s,csFontSize,Size);
  240.         WriteInteger(s,csFontColor,Color);
  241.         tmpStyles:=Style;
  242.         pStyles:=@TmpStyles;
  243.         WriteInteger(s,csFontStyle,integer(pStyles^));
  244.       end;
  245.       WriteBool(s,csReadOnly,ReadOnly);
  246.       WriteBool(s,csWordWrap,WordWrap);
  247.     end;
  248.     //ToolBar Section
  249.     with SrmForm.ControlBar do
  250.     begin
  251.       s:=Name;
  252.       n:=ControlCount-1;
  253.       for i:=0 to n do
  254.       with SrmForm.ControlBar.Controls[i] do
  255.       begin
  256.         WriteInteger(s,Name+csLeft,Left);
  257.         WriteInteger(s,Name+csTop,Top);
  258.       end;
  259.     end;
  260.     //StatusBar Section
  261.     with SrmForm.StatusBar do
  262.     begin
  263.       s:=Name;
  264.       WriteBool(s,csVisible,Visible);
  265.     end;
  266.     //File Section
  267.     WriteString(csFileSection,csMyLoveFile,MyLoveFile);
  268.     WriteString(csFileSection,csNearFile,NearFile);
  269.     WriteString(csFileSection,csFileList0,FileList[0]);
  270.     WriteString(csFileSection,csFileList1,FileList[1]);
  271.     WriteString(csFileSection,csFileList2,FileList[2]);
  272.     WriteString(csFileSection,csFileList3,FileList[3]);
  273.     WriteString(csFileSection,csFileList4,FileList[4]);
  274.     WriteBool(csFileSection,csOpenSrmWithApp,OpenSrmWithApp);
  275.     WriteBool(csFileSection,csLoadNearFile,LoadNearFile);
  276.     WriteBool(csFileSection,csMyLoveVisible,MyLoveVisible);
  277.     WriteBool(csFileSection,csFileListVisible,FileListVisible);
  278.     WriteBool(csFileSection,csSaveDbQuery,SaveDbQuery);
  279.     WriteBool(csFileSection,csDelRecordQuery,DelRecordQuery);
  280.   end;
  281.   Ini.Free;
  282. end;
  283. end.