Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion wxFileConfig question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Igor Korot  
View profile  
 More options Oct 26 2012, 6:20 pm
From: Igor Korot <ikoro...@gmail.com>
Date: Fri, 26 Oct 2012 15:20:51 -0700
Local: Fri, Oct 26 2012 6:20 pm
Subject: wxFileConfig question
Hi, ALL,
I am trying to write an application that uses wxFileConfig on both
Windows and Linux.
I made the test file called "test.ini" and placed it in the appropriate place.

test.ini:

[Device1]
URL=www.google.com
Port=10001

[Device2]
URL=www.google.com
Port=10002

Now in the code here is what I do:

wxFileConfig *config = new wxFileConfig( "test.ini" );
wxString oldPath = config->GetPath();
wxString path = "Device";
wxString address;
int port;
devicenum = config->GetNumberOfGroups();
for( size_t i = 1; i <= devicenum; i++ )
{
        config->SetPath( path << i );
        if( !config->Read( "Port", &port ) )
        {
                printf( "There is a problem with configuration file.\r\n" );
                printf( "No port supplied for the device #%d", i );
                delete config;
                return -1;
        }
        if( config->Read( "Address", &address ) )
        {
                devices.push_back( new Device( address, port, false ) );
        }
        else if( config->Read( "URL", &address ) )
        {
                devices.push_back( new Device( address, port, true ) );
        }
        else
        {
                printf( "There is a problem with configuration file.\r\n" );
                printf( "No address/URL supplied for the device #%d", i );
                delete config;
                return -1;
        }
        path = "Device";

}

config->SetPath( oldPath );

The problem is that the loop succeeds on the first iteration for the
"[Device1]", but fails to read
the data on the second iteration for "[Device2]".

However if I change the code to read:

for( size_t i = 1; i <= devicenum; i++ )
{
        wxString test = wxString::Format( "Device%d", i );
        if( !config->Read( test + "/Port", &port ) )
        {
                printf( "There is a problem with configuration file.\r\n" );
                printf( "No port supplied for the device #%d", i );
                delete config;
                return -1;
        }
        if( config->Read( test + "/Address", &address ) )
        {
                devices.push_back( new Device( address, port, false ) );
        }
        else if( config->Read( test + "/URL", &address ) )
        {
                devices.push_back( new Device( address, port, true ) );
        }

}

I can read both "Device1" and "Device2" parts.
Is this a known problem?

I'm currently on Windows (7) with wx-2.9.4 compiled with MSVC-2010.

Thank you.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.