www.pudn.com > srmsrc.zip > RegUnit.pas


//--------------------------------------------------------------------------- 
//(R)CopyRight KivenSoft International ,inc 1999 
//单元名称:读写注册表单元 
//程序名称:电子书库 
//作    者:李会文 
//开始时间:1999.07.01 
//最后修改:1999.07.06 
//备注:此单元定义了读写注册表中应用程序各种信息的单元,在应用程序初始时进行 
//--------------------------------------------------------------------------- 
unit RegUnit; 
 
interface 
uses 
  IniFiles, SysUtils, Forms, Graphics, MainUnit; 
 
type 
  TAppIni=class 
  private 
    FileName:string; 
  public 
    //数据库的各类设置 
    MyLoveFile                       :string;        //我的最爱数据库名 
    NearFile                         :string;        //上次关闭时的数据库名 
    FileList                         :array[0..4] of string;//最近打开的5个文件 
    OpenSrmWithApp                   :boolean;       //SRM文件是否用应用程序打开 
    LoadNearFile                     :boolean;       //运行时是否装入上次打开的数据库 
    MyLoveVisible                    :boolean;       //菜单上我的最爱是否显示 
    FileListVisible                  :boolean;       //最近打开文件列表是否显示 
    SaveDbQuery                      :boolean;       //保存数据库前是否提示 
    DelRecordQuery                   :boolean;       //删除记录前是否提示 
    //类成员函数 
    constructor Create; 
    destructor Destroy;override; 
  end; 
 
const 
  csWidth='Width'; 
  csHeight='Height'; 
  csLeft='Left'; 
  csTop='Top'; 
  csState='State'; 
  csVisible='Visible'; 
  csColor='Color'; 
  csFontName='FontName'; 
  csFontSize='FontSize'; 
  csFontColor='FontColor'; 
  csFontStyle='FontStyle'; 
  csReadOnly='Edit'; 
  csWordWrap='WordWrap'; 
 
  csFileSection='File'; 
  csMyLoveFile='MyLoveFile'; 
  csNearFile='NearFile'; 
  csFileList0='FileList0'; 
  csFileList1='FileList1'; 
  csFileList2='FileList2'; 
  csFileList3='FileList3'; 
  csFileList4='FileList4'; 
  csOpenSrmWithApp='OpenSrmWithApp'; 
  csLoadNearFile='LoadNearFile'; 
  csMyLoveVisible='MyLoveVisible'; 
  csFileListVisible='FileListVisible'; 
  csSaveDbQuery='SaveDbQuery'; 
  csDelRecordQuery='DelRecordQuery'; 
 
var 
  AppIni:TAppIni; 
 
implementation 
 
 
constructor TAppIni.Create; 
var 
  i,n:integer; 
  Ini:TIniFile; 
  pStyles:pointer; 
  s:string; 
begin 
  //求出应用程序的INI文件名 
  FileName:=Application.ExeName; 
  n:=Length(FileName); 
  FileName[n-2]:='i'; 
  FileName[n-1]:='n'; 
  FileName[n]  :='i'; 
  FileName:=LowerCase(FileName); 
 
  Ini:=TIniFile.Create(FileName); 
  with Ini do 
  begin 
    //MainFrom Section 
    with SrmForm do 
    begin 
      s:=Name; 
      SetBounds(ReadInteger(s,csLeft,0), 
                ReadInteger(s,csTop,0), 
                ReadInteger(s,csWidth,Width), 
                ReadInteger(s,csHeight,Height)); 
      WindowState:=TWindowState(ReadInteger(s,csState,integer(WindowState))); 
    end; 
    //LeftFrom Section 
    with SrmForm.LeftForm do 
    begin 
      s:=Name; 
      Width:=ReadInteger(s,csWidth,Width); 
      Visible:=ReadBool(s,csVisible,Visible); 
    end; 
    //TreeView Section 
    with SrmForm.TreeView do 
    begin 
      s:=Name; 
      Color:=ReadInteger(s,csColor,Color); 
      with SrmForm.TreeView.Font do 
      begin 
        Name:=ReadString(s,csFontName,Name); 
        Size:=ReadInteger(s,csFontSize,Size); 
        Color:=ReadInteger(s,csFontColor,Color); 
        n:=ReadInteger(s,csFontStyle,0); 
        pStyles:=@n; 
        Style:=TFontStyles(pStyles^); 
      end; 
    end; 
    //RichEdit Section 
    with SrmForm.RichEdit do 
    begin 
      s:=Name; 
      Color:=ReadInteger(s,csColor,Color); 
      with SrmForm.RichEdit.Font do 
      begin 
        Name:=ReadString(s,csFontName,Name); 
        Size:=ReadInteger(s,csFontSize,Size); 
        Color:=ReadInteger(s,csFontColor,Color); 
        n:=ReadInteger(s,csFontStyle,0); 
        pStyles:=@n; 
        Style:=TFontStyles(pStyles^); 
      end; 
      ReadOnly:=ReadBool(s,csReadOnly,ReadOnly); 
      WordWrap:=ReadBool(s,csWordWrap,WordWrap); 
    end; 
    //ToolBar Section 
    with SrmForm.ControlBar do 
    begin 
      s:=Name; 
      n:=ControlCount-1; 
      for i:=0 to n do 
      with SrmForm.ControlBar.Controls[i] do 
      begin 
        Left:=ReadInteger(s,Name+csLeft,Left); 
        Top:=ReadInteger(s,Name+csTop,Top); 
      end; 
    end; 
    //StatusBar Section 
    with SrmForm.StatusBar do 
    begin 
      s:=Name; 
      Visible:=ReadBool(s,csVisible,Visible); 
    end; 
    //ToolBar SpeedButton 
    with SrmForm do 
    begin 
      TitleToolButton.Down:=LeftForm.Visible; 
      ReadOnlyToolButton.Down:=RichEdit.ReadOnly; 
    end; 
    //File Section 
    MyLoveFile:=ReadString(csFileSection,csMyLoveFile,''); 
    NearFile:=ReadString(csFileSection,csNearFile,''); 
    FileList[0]:=ReadString(csFileSection,csFileList0,''); 
    FileList[1]:=ReadString(csFileSection,csFileList1,''); 
    FileList[2]:=ReadString(csFileSection,csFileList2,''); 
    FileList[3]:=ReadString(csFileSection,csFileList3,''); 
    FileList[4]:=ReadString(csFileSection,csFileList4,''); 
    OpenSrmWithApp:=ReadBool(csFileSection,csOpenSrmWithApp,true); 
    LoadNearFile:=ReadBool(csFileSection,csLoadNearFile,true); 
    MyLoveVisible:=ReadBool(csFileSection,csMyLoveVisible,true); 
    FileListVisible:=ReadBool(csFileSection,csFileListVisible,true); 
    SaveDbQuery:=ReadBool(csFileSection,csSaveDbQuery,true); 
    DelRecordQuery:=ReadBool(csFileSection,csDelRecordQuery,true); 
    //MainMenu 
    with SrmForm do 
    begin 
      StatusMenuItem.Checked:=StatusBar.Visible; 
      TitleMenuItem.Checked:=LeftForm.Visible; 
      ReadOnlyMenuItem.Checked:=RichEdit.ReadOnly; 
    end; 
  Ini.Free; 
  end; 
end; 
 
destructor TAppIni.Destroy; 
var 
  i,n:integer; 
  Ini:TIniFile; 
  tmpStyles:TFontStyles; 
  pStyles:pointer; 
  s:string; 
begin 
  Ini:=TIniFile.Create(FileName); 
  with Ini do 
  begin 
    //MainFrom Section 
    with SrmForm do 
    begin 
      s:=Name; 
      WriteInteger(s,csState,integer(WindowState)); 
      if WindowState<>wsNormal then  //如果不为正常的话, 
      begin 
      WriteInteger(s,csWidth,540) ;  //设为一个常值 
      WriteInteger(s,csHeight,411); 
      WriteInteger(s,csLeft,Screen.Height div 2); //各为桌面的一半! 
      WriteInteger(s,csTop,Screen.Width div 2) 
      end 
      else 
      begin 
      WriteInteger(s,csWidth,Width); 
      WriteInteger(s,csHeight,Height); 
      WriteInteger(s,csLeft,Left); 
      WriteInteger(s,csTop,Top); 
    end; 
    end; 
    //LeftFrom Section 
    with SrmForm.LeftForm do 
    begin 
      s:=Name; 
      WriteInteger(s,csWidth,Width); 
      WriteBool(s,csVisible,Visible); 
    end; 
    //TreeView Section 
    with SrmForm.TreeView do 
    begin 
      s:=Name; 
      WriteInteger(s,csColor,Color); 
      with SrmForm.TreeView.Font do 
      begin 
        WriteString(s,csFontName,Name); 
        WriteInteger(s,csFontSize,Size); 
        WriteInteger(s,csFontColor,Color); 
        tmpStyles:=Style; 
        pStyles:=@TmpStyles; 
        WriteInteger(s,csFontStyle,integer(pStyles^)); 
      end; 
    end; 
    //RichEdit Section 
    with SrmForm.RichEdit do 
    begin 
      s:=Name; 
      WriteInteger(s,csColor,Color); 
      with SrmForm.RichEdit.Font do 
      begin 
        WriteString(s,csFontName,Name); 
        WriteInteger(s,csFontSize,Size); 
        WriteInteger(s,csFontColor,Color); 
        tmpStyles:=Style; 
        pStyles:=@TmpStyles; 
        WriteInteger(s,csFontStyle,integer(pStyles^)); 
      end; 
      WriteBool(s,csReadOnly,ReadOnly); 
      WriteBool(s,csWordWrap,WordWrap); 
    end; 
    //ToolBar Section 
    with SrmForm.ControlBar do 
    begin 
      s:=Name; 
      n:=ControlCount-1; 
      for i:=0 to n do 
      with SrmForm.ControlBar.Controls[i] do 
      begin 
        WriteInteger(s,Name+csLeft,Left); 
        WriteInteger(s,Name+csTop,Top); 
      end; 
    end; 
    //StatusBar Section 
    with SrmForm.StatusBar do 
    begin 
      s:=Name; 
      WriteBool(s,csVisible,Visible); 
    end; 
    //File Section 
    WriteString(csFileSection,csMyLoveFile,MyLoveFile); 
    WriteString(csFileSection,csNearFile,NearFile); 
    WriteString(csFileSection,csFileList0,FileList[0]); 
    WriteString(csFileSection,csFileList1,FileList[1]); 
    WriteString(csFileSection,csFileList2,FileList[2]); 
    WriteString(csFileSection,csFileList3,FileList[3]); 
    WriteString(csFileSection,csFileList4,FileList[4]); 
    WriteBool(csFileSection,csOpenSrmWithApp,OpenSrmWithApp); 
    WriteBool(csFileSection,csLoadNearFile,LoadNearFile); 
    WriteBool(csFileSection,csMyLoveVisible,MyLoveVisible); 
    WriteBool(csFileSection,csFileListVisible,FileListVisible); 
    WriteBool(csFileSection,csSaveDbQuery,SaveDbQuery); 
    WriteBool(csFileSection,csDelRecordQuery,DelRecordQuery); 
  end; 
  Ini.Free; 
end; 
 
end.