Ini文件类型名称预期的C++

huangapple go评论82阅读模式
英文:

Ini file Type name Expected C++

问题

我希望你能帮助我解决这个编译错误。

我试图测试从Embarcadero官方文档网站提取的代码,旨在测试TIniFile类。

但是我得到了这个错误:

Unit2.cpp(76): parsing: TCustomIniFile * _fastcall Form2::OpenIniFileInstance().

以下是我的代码:

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#include <IniFiles.hpp>

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;

__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}

void __fastcall TForm2::btStoreClickClick(TObject *Sender)
{
    //首次编辑文件
    /* 打开一个实例 */
    TCustomIniFile* SettingsFile = OpenIniFileInstance();

    // 存储当前窗体属性,以在以后的会话中使用。
    try
    {
        SettingsFile->WriteInteger(Name, "Top", Top);
        SettingsFile->WriteInteger(Name, "Left", Left);
        SettingsFile->WriteInteger(Name, "Width", Width);
        SettingsFile->WriteInteger(Name, "Height", Height);
        SettingsFile->WriteString(Name, "Caption", Caption);
        SettingsFile->WriteBool(Name, "InitMax", WindowState == wsMaximized);
    }
    catch(Exception* e)
    {
    }

    delete SettingsFile;
}

void __fastcall TForm2::btLoadClick(TObject *Sender)
{
    TCustomIniFile* SettingsFile = OpenIniFileInstance();

    try
    {
        /*
        读取上次会话保存的所有值。部分名称
        是窗体的名称。还使用窗体的属性作为默认值
        */
        Top     = SettingsFile->ReadInteger(Name, "Top", Top );
        Left    = SettingsFile->ReadInteger(Name, "Left", Left );
        Width   = SettingsFile->ReadInteger(Name, "Width", Width );
        Height  = SettingsFile->ReadInteger(Name, "Height", Height );
        Caption = SettingsFile->ReadString(Name, "Caption", Caption);

        // 加载上次的窗口状态
        if (SettingsFile->ReadBool(Name, "InitMax", WindowState == wsMaximized))
            WindowState = wsMaximized;
        else
            WindowState = wsNormal;
    }
    catch(Exception* e)
    {
    }

    delete SettingsFile;
}

TCustomIniFile* __fastcall TForm2::OpenIniFileInstance()
{
    TCustomIniFile* temp;
    switch (RadioGroup1->ItemIndex)
    {
        case 0: {
                /* 选择注册表模式:在HKEY_CURRENT_USER\Software\... */
            temp = new TRegistryIniFile(String("Software\\") + Application->Title);
        }  
            break;
        case 1: {
                /* 选择Ini文件模式 */
            temp = new TIniFile(ChangeFileExt(Application->ExeName, ".INI"));
        }
            break;
        case 2: {
                /* 选择基于内存的Ini文件模式 */
            temp = new TMemIniFile(ChangeFileExt(Application->ExeName, ".INI"));
        }
            break;
        default:
            break;
    }
    return temp;
}
英文:

I hope that you can help me to resolve this compilation error.

I'm trying to test code taken from Embarcadero's official documentation website, which has at aim to test the TIniFile class.

However I get this error:

Unit2.cpp(76): parsing: TCustomIniFile * _fastcall Form2::OpenIniFileInstance().

Below is my code:

#include &lt;vcl.h&gt;
#pragma hdrstop
#include &quot;Unit2.h&quot;
#include &lt;IniFiles.hpp&gt;
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm2 *Form2;
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm2::btStoreClickClick(TObject *Sender)
{
//First Edit of the file
/* Open an instance */
TCustomIniFile* SettingsFile = OpenIniFileInstance();
// Store current form properties to be used in later sessions.
try
{
SettingsFile-&gt;WriteInteger (Name, &quot;Top&quot;, Top);
SettingsFile-&gt;WriteInteger (Name, &quot;Left&quot;, Left);
SettingsFile-&gt;WriteInteger (Name, &quot;Width&quot;, Width);
SettingsFile-&gt;WriteInteger (Name, &quot;Height&quot;, Height);
SettingsFile-&gt;WriteString  (Name, &quot;Caption&quot;, Caption);
SettingsFile-&gt;WriteBool    (Name, &quot;InitMax&quot;, WindowState == wsMaximized );
}
catch(Exception* e)
{
}
delete SettingsFile;
}
void __fastcall TForm2::btLoadClick(TObject *Sender)
{
TCustomIniFile* SettingsFile = OpenIniFileInstance();
try
{
/*
Read all saved values from the last session. The section name
is the name of the form. Also use form&#39;s properties as defaults
*/
Top     = SettingsFile-&gt;ReadInteger(Name, &quot;Top&quot;, Top );
Left    = SettingsFile-&gt;ReadInteger(Name, &quot;Left&quot;, Left );
Width   = SettingsFile-&gt;ReadInteger(Name, &quot;Width&quot;, Width );
Height  = SettingsFile-&gt;ReadInteger(Name, &quot;Height&quot;, Height );
Caption = SettingsFile-&gt;ReadString (Name, &quot;Caption&quot;, Caption);
// Load last window state
if (SettingsFile-&gt;ReadBool(Name, &quot;InitMax&quot;, WindowState == wsMaximized))
WindowState = wsMaximized;
else
WindowState = wsNormal;
}
catch(Exception* e)
{
}
delete SettingsFile;
}
TCustomIniFile* __fastcall TForm2::OpenIniFileInstance()
{
TCustomIniFile* temp;
switch (RadioGroup1-&gt;ItemIndex)
{
case 0: {
/* Registry mode selected: in HKEY_CURRENT_USER\Software\... */
temp = new TRegistryIniFile(String(&quot;Software\\&quot;) + Application-&gt;Title);
}  
break;
case 1: {
/* Ini file mode selected */
temp = new TIniFile(ChangeFileExt(Application-&gt;ExeName, &quot;.INI&quot;));
}
break;
case 2: {
/* Memory based Ini file mode selected */
temp = new TMemIniFile(ChangeFileExt(Application-&gt;ExeName, &quot;.INI&quot;));
}
break;
default:
break;
}
return temp;
}

答案1

得分: 1

谢谢大家。
我已找到解决此问题的方法。我错过了头文件#include&lt;System.Win.Registry.hpp&gt;

最好的祝愿。

英文:

Thanks everybody.
I have find the solution to resolve this issue. I miss the header file #include&lt;System.Win.Registry.hpp&gt;

Best regards.

huangapple
  • 本文由 发表于 2020年1月3日 18:09:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定