怎么使用MDI?(100分)

  • 主题发起人 litterbug
  • 开始时间
L

litterbug

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用多文档界面开发一个系统。<br><br>在新建一个子窗口后,在子窗口里有数据库控件,树型目录,以及输入的数据,我要怎样<br>保存此时的环境,以便下次打开是仍然保留有上次的环境!<br><br>好像子窗口只能处理文本或者图形,我还没见到保存数据环境的相关例子!如果哪位大虾有<br>这方面的例子,请告知,谢谢!<br>
 
狂人工作站上有.你搜一下。
 
MDI使用:<br>在主Form的FormSytle为fsMDIForm;子Form的FormSytle为fsMDIChild。<br>
 
用写ini文件或注册表的方式,在窗体OnShow事件和OnClose分别记录下窗体的<br>self.Left, self.Top, self.Width, self.Height这四个参数<br><br><br>1.下面是读写注册表的方式(读写键值是string, 用strToInt, 和 IntToStr进行转换)<br>function htwReadRegisry( RegKey :string ; Default :string ; MyRootKey : Hkey; &nbsp;MyOpenKey :string): string &nbsp;;<br>var<br>&nbsp; &nbsp;Registry: TRegistry;<br>&nbsp; &nbsp;S : string;<br>begin<br>&nbsp; &nbsp;Registry:= TRegistry.Create;<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.RootKey :=MyRootKey; &nbsp; // HKEY_CURRENT_USER;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.OpenKey(MYOpenKey,false); &nbsp;// Registry.OpenKey('/Software/MachineAdministrator',false);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;S := Registry.ReadString(RegKey);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.CloseKey;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.Free;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if Trim(S)='' &nbsp;then Result := Default<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp; Result := S;<br>&nbsp; &nbsp;end;<br><br>end;<br><br>procedure htwWriteRegisry(RegKey :string ;asValueTobewrited : string; MyRootKey : Hkey; &nbsp;MyOpenKey :string );<br>var<br>&nbsp; &nbsp;Registry: TRegistry;<br>begin<br>&nbsp; &nbsp;Registry:= TRegistry.Create;<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.RootKey :=MyRootKey; // HKEY_CURRENT_USER;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.OpenKey(MyOpenKey,true); //Registry.OpenKey('/Software/MachineAdministrator',true);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.WriteString(RegKey,asValueTobewrited);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.CloseKey;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Registry.Free;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br>end;<br><br>调用方法:<br>&nbsp; try<br>&nbsp; &nbsp; htwWriteRegisry('sShortDate','yyyy-MM-dd' ,HKEY_CURRENT_USER, '/Control Panel/International');<br>&nbsp; &nbsp; htwWriteRegisry('sShortDate','yyyy-MM-dd' ,HKEY_USERS, '/.DEFAULT/Control Panel/International');<br>&nbsp; &nbsp; setlocaleinfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SDATE,'yyyy-MM-dd');<br>&nbsp; except<br>&nbsp; end;<br><br>2.下面是读写ini文件的方式(用的是API):<br><br>要利用.INI文件做程序有关数据的存储工作,就需要能读和写.INI文件,所以列了如下方法给大家参考:<br>从.INI文件中获取字符串<br>var<br>strResult:pchar;<br>begin<br>GetPrivateProfileString(<br>'windows', // []中标题的名字<br>'NullPort', // =号前的名字<br>'NIL', // 如果没有找到字符串时,返回的默认值<br>strResult, //存放取得字符<br>100, //取得字符的允许最大长度<br>'c:/forwin95/win.ini' // 调用的文件名<br>);<br>edit1.text:=strResult; //显示取得字符串<br>从.INI文件中获取整数<br>edit1.text:=inttostr(GetPrivateProfileInt(<br>'intl', // []中标题的名字<br>'iCountry', // =号前的名字<br>0,// 如果没有找到整数时,返回的默认值<br><br>'c:/forwin95/win.ini' // 调用的文件名<br>));<br>向.INI文件写入字符串<br>WritePrivateProfileString(<br>'windows', // []中标题的名字<br>'load', // 要写入“=”号前的字符串<br>'accca', //要写入的数据<br>'c:/forwin95/win.ini' // 调用的文件名<br>);<br>向.INI文件写入整数<br>WritePrivateProfileSection(<br>'windows', // []中标题的名字<br>'read=100', // 要写入的数据<br>'c:/forwin95/win.ini' // 调用的文件名<br>);<br><br><br>
 
接受答案了.
 
顶部