社区
C++ Builder
帖子详情
求BCB操纵INI文件的函数详解,知道的兄台,先行谢过了
wangyelon
2002-08-13 05:16:31
所有看此帖的兄台(姐妹?)都是我要谢谢的!
我在写一个管理信息系统,想把界面的设置保存下来,
例如我在MainForm里放了几个各自实现一部分功能的Frame,
默认是有一个显示其他的都藏起来 ,运行时可以选需要的,
如果退出时记录所选的,下次就很直接了,ini我不熟悉.
So please!
...全文
137
11
打赏
收藏
求BCB操纵INI文件的函数详解,知道的兄台,先行谢过了
所有看此帖的兄台(姐妹?)都是我要谢谢的! 我在写一个管理信息系统,想把界面的设置保存下来, 例如我在MainForm里放了几个各自实现一部分功能的Frame, 默认是有一个显示其他的都藏起来 ,运行时可以选需要的, 如果退出时记录所选的,下次就很直接了,ini我不熟悉. So please!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
iamleejun
2002-10-24
打赏
举报
回复
mark
iamleejun
2002-10-24
打赏
举报
回复
mark
iamleejun
2002-10-24
打赏
举报
回复
mark
kingcaiyao
2002-08-13
打赏
举报
回复
一个简单的INI文件有必要这么麻烦吗?
COKING
2002-08-13
打赏
举报
回复
建议你保存到xml文件里!
wangyelon
2002-08-13
打赏
举报
回复
上面这位大侠意思我明白,不过好向没必要这样大费周章.哈.
xiaoguoru
2002-08-13
打赏
举报
回复
我觉得得不一定要用TIniFile也可以操作*.ini文件,下面我给一个例子:
int count ;
count = ListView->Items->Count ;
*insertcount = count;
*totaltime = slength;
if(StrToInt(ListView->Items->Item[count-1]->SubItems->Strings[1]) >= slength)//ListView 是TListView控件.
{
int insert[2],end,begin, run = 0 ,sb = 0;
bool issame = false;
if(StrToInt(ListView->Items->Item[count-1]->SubItems->Strings[1]) >= slength) //插入文件里有的插入点大于被插入文件的长度
{
TStringList *List = new TStringList();
List->Clear();
for(int i = 0; i < count;i++)
{
insert[0] = StrToInt(ListView->Items->Item[i]->SubItems->Strings[1]);
//insert[1] = StrToInt(ListView->Items->Item[i]->SubItems->Strings[1]);
begin = StrToInt(ListView->Items->Item[i]->SubItems->Strings[2]);
end = StrToInt(ListView->Items->Item[i]->SubItems->Strings[3]);
if(insert[0] >= slength)//插入文件的插入点大于被插入文件的长度
{
for(int j = i; j < count;j++)
{
*totaltime = *totaltime + run;
List->Add(ListView->Items->Item[j]->SubItems->Strings[0]
+ ListView->Items->Item[j]->Caption);
List->Add(ListView->Items->Item[j]->SubItems->Strings[1]); //加入插入点
List->Add(ListView->Items->Item[j]->SubItems->Strings[2]);
List->Add(ListView->Items->Item[j]->SubItems->Strings[3]);
*totaltime = *totaltime + StrToInt(ListView->Items->Item[j]->SubItems->Strings[3])
- StrToInt(ListView->Items->Item[j]->SubItems->Strings[2]);
}
if(FileExists(Path+"\\InsertFilePoint.ini"))//Path是一个全局变量,它代表应用程序的路径.
{ DeleteFile(Path+"\\InsertFilePoint.ini");
List->SaveToFile(Path+"\\InsertFilePoint.ini");
}
else
List->SaveToFile(Path+"\\InsertFilePoint.ini");
break;
}
else //插入文件的插入点小于被插入文件的长度
{
List->Add(ListView->Items->Item[i]->SubItems->Strings[0]
+ ListView->Items->Item[i]->Caption);
List->Add(IntToStr(insert[0]+ run));
List->Add(IntToStr(begin));
List->Add(IntToStr(end));
if(!issame)
{
sb = insert[0];
}
run = run + end - begin;
insert[1] = StrToInt(ListView->Items->Item[i+1]->SubItems->Strings[1]);
if(insert[0] == insert[1])
{
issame = true;
}
else
{
*insertcount = *insertcount+1;
List->Add(edtSource->Text);
List->Add(IntToStr(insert[0]+run));
List->Add(IntToStr(sb));
List->Add(IntToStr(slength));
issame = false;
}
}
}
}
}
else //所有插入点均小于被插入文件的总长
{
int insert[2],end,begin, run = 0,sb = 0;
bool issame = false;
TStringList *List = new TStringList();
List->Clear();
for(int i = 0 ;i < count; i++)
{
insert[0] = StrToInt(ListView->Items->Item[i]->SubItems->Strings[1]);
begin = StrToInt(ListView->Items->Item[i]->SubItems->Strings[2]);
end = StrToInt(ListView->Items->Item[i]->SubItems->Strings[3]);
List->Add(ListView->Items->Item[i]->SubItems->Strings[0]
+ ListView->Items->Item[i]->Caption);
List->Add(IntToStr(insert[0]+ run));
List->Add(IntToStr(begin));
List->Add(IntToStr(end));
if(!issame)
{
sb = insert[0];
}
run = run + end - begin;
if(i == count-1) //最后一个
{
*insertcount = *insertcount+1;
List->Add(edtSource->Text);
List->Add(IntToStr(insert[0]+run));
List->Add(IntToStr(sb));
List->Add(IntToStr(slength));
*totaltime = *totaltime + run;
break;
}
else
{
insert[1] = StrToInt(ListView->Items->Item[i+1]->SubItems->Strings[1]);
if(insert[0] == insert[1])
{
issame = true;
}
else
{
*insertcount = *insertcount+1;
List->Add(edtSource->Text);
List->Add(IntToStr(insert[0]+run));
List->Add(IntToStr(sb));
List->Add(IntToStr(slength));
issame = false;
}
}
}
if(FileExists(Path+"\\InsertFilePoint.ini"))
{
DeleteFile(Path+"\\InsertFilePoint.ini");
List->SaveToFile(Path+"\\InsertFilePoint.ini");
}
else
{
List->SaveToFile(Path+"\\InsertFilePoint.ini");
}
}
然后在你读出来时也是一行一行读,它是零行开始的.
wangyelon
2002-08-13
打赏
举报
回复
帮助里例子的我看了,不过还是感谢热心人!
mygodness
2002-08-13
打赏
举报
回复
我的经验:
1、首先要在加入包含文件:#include <inifiles.hpp>
2、在BCB里有一个TIniFile的类,使用时可以创建这样一个类:TIniFile *ini;ini=new TIniFile(FileName);
3、在TIniFile类里,唯一的属性就是FileName,这是一个AnsiString类型的参数。
4、读INI文件时,例如读字符串可用TIniFile的以下方法:
AnsiString a;a=ini->ReadString(const AnsiString Section, const AnsiString Ident,
const AnsiString Default);Section就是分部的名称,Ident是要读的值名称,Default是读取发生错误时的默认值。
5、其它读值的方法还有:ReadBool
ReadDate
ReadDateTime
ReadFloat
ReadInteger
ReadTime
使用方法基本相同。
6、 设置值时:可用的方法有WriteString
WriteBool
WriteDate
WriteDateTime
WriteFloat
WriteInteger
WriteTime
7、以writeString为例:ini->WriteString(AnsiString Section,AnsiString Ident,AnsiString value);其中value是要写入的值。其它参数和读值时是相同的意思。
8、其它还有些比较有用的方法有ReadSection,ReadSections分别读取某部分的值名列表,和读取所有部分的值名列表。
9、使用完之后,别忘记释放资源:delete ini;
gfh21cn
2002-08-13
打赏
举报
回复
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TIniFile *pIniFile = new TIniFile("c:\MyApp\bin\MyApp.ini");
if (pIniFile->ReadBool("AutoLoad", "FormProperties", false) == true)
{
Visible = pIniFile->ReadBool("FormOptions", "Visible", true);
Color = (Graphics::TColor)pIniFile->ReadInteger("FormOptions", "Color", clWindow);
Caption = pIniFile->ReadString("FormOptions", "Caption", "Main");
}
delete pIniFile;
}
呵呵,其实这些都是帮助里
gfh21cn
2002-08-13
打赏
举报
回复
#include <Inifiles.hpp>
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TIniFile* pif = new TIniFile("WIN.INI");
pif->ReadSections(ListBox1->Items);
pif->ReadSection("Ports",ListBox2->Items);
pif->ReadSectionValues("Ports",ListBox3->Items);
delete pif;
}
BCB
对如何操作
ini
文件
?
.
ini
文件
是
Ini
tialization File的缩写,即初始化
文件
,是windows的系统配置
文件
所采用的存储格式,统管windows的各项配置,在实际开发中,
ini
文件
的应用也是非常广泛的。 下面来利用
BCB
来操作一下
ini
文件
: //-------------------------------------------------------------------
BCB
的
文件
操作
函数
BCB
的
函数
: 1. FileOpen 打开指定的
文件
,如果返回为正数,表示操作成功,返回值为
文件
句柄:如果返回值为-1,表 示操作失败,
函数
原型如下: int __fastcall FileOpen(const System::AnsiString FileName,int Mode); 2. F
BCB
文件
夹copy
函数
(包括
文件
夹下所有
文件
和子
文件
夹)
【代码】
BCB
文件
夹copy
函数
(包括
文件
夹下所有
文件
和子
文件
夹)
用
BCB
读写文本
文件
及
ini
配置
文件
在头
文件
中加上#include "
Ini
Files.hpp"//读写文本
文件
//--写入文本
文件
//----------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender){char dir[MAX_PATH];char *tfile = "/nei.txt";
C++
文件
操作之三 :
BCB
提供的
文件
操作的库
函数
三、
BCB
提供的
文件
操作的库
函数
。 在
BCB
中也提供了
文件
操作的
函数
,这些
函数
的功能和前面所介绍的大致相同,但这类
函数
和
BCB
关系紧密,能使用
BCB
中的AnsiString等数据类型,在
BCB
中用这种方式的
文件
操作是最方便的,下面我就把这种
文件
操作详细介绍。 在
BCB
提供的这组
文件
操作
函数
中,可分为三种类型,就是:1、
文件
名
函数
,2、
文件
管理
函数
;3、
文件
I/O
函数
。 1、
文件
名
函数
C++ Builder
13,870
社区成员
102,693
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章