WriteformState()ReadformState()

uses IniFiles;//引用IniFiles
 
{写入信息到ini文件 }
//WriteformState('Config.ini','MainForm',Form1)
procedure  WriteformState ( fileName : string ; section : string ; form : TForm );
var   INIFILE :  TIniFile ; 
begin
     INIFILE := TIniFile . Create ( ExtractFilePath ( Application . ExeName )+ fileName ); 
     try
      INIFILE . WriteInteger ( section , 'Left' ,   form . Left );
      INIFILE . WriteInteger ( section , 'Top' ,    form . Top );
      INIFILE . WriteInteger ( section , 'Height' , form . Height ); 
      INIFILE . WriteInteger ( section , 'width' ,  form . Width ); 
     Finally  
      INIFILE . Free ; 
     end ;  
end ;  


{从Ini读取信息并赋值}
//ReadformState('Config.ini','MainForm',Form1)
procedure  ReadformState ( fileName : string ; section : string ; form : TForm );
var 
  INIFILE :  TIniFile ; 
  frm1Left , frm1Top : integer ;  
begin
   form . Position := poDesigned ;
   //FORM1 处于屏幕中心点时的left Top的值 用于第1次运行本程序时程序出现 在屏幕中心 
   frm1Left :=( Screen . Width - FORM . Width )  div  2 ; 
   frm1Top  :=( Screen . Height - FORM . Height )  div  2 ; 
   INIFILE  := TIniFile . Create ( ExtractFilePath ( Application . ExeName )+ fileName ); 
     try  
          form . Left :=  INIFILE . ReadInteger ( section , 'Left' ,   frm1Left ); 
           form . Top :=  INIFILE . ReadInteger ( section , 'Top' ,    frm1Top ); 
        form . Height :=  INIFILE . ReadInteger ( section , 'Height' , form . Height ); 
         form . Width :=  INIFILE . ReadInteger ( section , 'Width' ,  form . Width ); 
     Finally 
       INIFILE . Free ; 
     end ;  
end ; 
粘贴自: < ">http://www.cnpack.org/ >
 




你可能感兴趣的:(write)