建立、读取、存贮INI文件的方法《二》

来源:互联网 发布:网络报警吧 编辑:程序博客网 时间:2024/04/19 10:25
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

内容:  

    要利用.INI文件做程序有关数据的存储工作,就需要能读和写.INI
文件,所以列了如下方法给大家参考:
从.INI文件中获取字符串
var
strResult:pchar;
begin
GetPrivateProfileString(
'windows', // []中标题的名字
'NullPort', // =号前的名字
'NIL', // 如果没有找到字符串时,返回的默认值
strResult, //存放取得字符
100, //取得字符的允许最大长度
'c:forwin95win.INI' // 调用的文件
);
edit1.text:=strResult; //显示取得字符串
从.INI文件中获取整数
edit1.text:=inttostr(GetPrivateProfileInt(
'intl', // []中标题的名字
'iCountry', // =号前的名字
0,// 如果没有找到整数时,返回的默认值
'c:forwin95win.INI' // 调用的文件
));
向.INI文件写入字符串
WritePrivateProfileString(
'windows', // []中标题的名字
'load', // 要写入“=”号前的字符串
'accca', //要写入的数据
'c:forwin95win.INI' // 调用的文件
);
向.INI文件写入整数
WritePrivateProfileSection(
'windows', // []中标题的名字
'read=100', // 要写入的数据
'c:forwin95win.INI' // 调用的文件
);
上面的方法是调用API函数,下面介绍另一种不用API从.INI文件
获取字符的方法
var MyINI: TINIFile;
begin
MyINI := TINIFile.Create('WIN.INI');//调用的文件
edit1.text:=MyINI.ReadString('Desktop', 'Wallpaper', '');//
取得字符
end;
向.INI文件中写入字符的方法
var MyINI: TINIFile;
begin
MyINI := TINIFile.Create('WIN.INI');//调用的文件
DelphiINI.WriteString('Desktop', 'Wallpaper', 'c:a.bmp');
end;

 

当然,这十分容易并破解,你可以用XOR进行异或操作,或者倒取反
值...具体的要看你怎么实现了.总之,本文章只抛砖引玉罢了.

 

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>