ReadString读INI文件的问题

fkueffff20070302 2011-03-23 09:28:05
我有一个INI文件,内容如下:
[Form]
Data Source=192.168.1.100
ID=sa
Password=070302
DataBase=AoKai

我怎么用ReadString读出上面几个值呢?如
Edit1->Text=ini->ReadString("Form","Data Source",变量);
192.168.1.100怎么用变量代呀??
...全文
431 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
魔方幻影 2011-03-25
  • 打赏
  • 举报
回复

TIniFile *IniKey;
AnsiString ExePath = ExtractFilePath(ParamStr(0));
IniKey = new TIniFile (ExePath + "/config.ini");
Edit1->Text = IniKey->ReadString("Form","Data Source",ExePath).Trim();
delete IniKey;
bigfog 2011-03-24
  • 打赏
  • 举报
回复
没默认就用空值,如下
Edit1->Text = ini->ReadString("Form", "Data Source", "");
ccrun.com 2011-03-24
  • 打赏
  • 举报
回复
String strDefault = "192.168.1.100";
Edit1->Text = ini->ReadString("Form", "Data Source", strDefault);
xjq2003 2011-03-24
  • 打赏
  • 举报
回复
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;
}

virtual AnsiString __fastcall ReadString(const AnsiString Section, const AnsiString Ident, const AnsiString Default);

Description

Call ReadString to read a string value from an INI file. Section identifies the section in the file that contains the desired key. Ident is the name of the key from which to retrieve the value. Default is the string value to return if the:

Section does not exist.

Key does not exist.
Data value for the key is not assigned.

The ReadString method inherited from TCustomIniFile is modified to operate on the in-memory copy of the INI file data. The read methods for all other data types use ReadString internally and then translate to the appropriate data type.
xjq2003 2011-03-24
  • 打赏
  • 举报
回复
Edit1->Text=ini->ReadString("Form","Data Source",变量);
你说的“变量”不是将数据给“变量”,而是将“变量”内容做为默认值。

这里“变量”可以使用String类型的
Persistent8813 2011-03-24
  • 打赏
  • 举报
回复
那地方是默认值,可以用""或一个固定值
hyz_cs 2011-03-23
  • 打赏
  • 举报
回复
你上面"变量"位置应该是默认返回值的参数吧,也就是没有"Data Source"这一项时情函数的返回值.

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧