Author Topic: GetUserVariableManager().Exists() question  (Read 3003 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5736
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
GetUserVariableManager().Exists() question
« on: April 07, 2013, 02:32:39 am »
I'm creating a wizard for OpenCV library, but have problem handling paths, so I read the related part of script in wxWidgets wizard, it is in <C::B>\share\CodeBlocks\templates\wizard\wxwidgets\wizard.script

// wxWidgets' path page

function OnLeave_WxPath(fwd)
    if (fwd)
        local dir         = Wizard.GetTextControlValue(_T("txtFolder"));
        local dir_nomacro = ReplaceMacros(dir, true);
        if (!IO.FileExists(dir_nomacro + _T("/include/wx/wx.h")))
            ShowError(_T("The path you entered seems valid, but this wizard " +
                    "can't locate wxWidgets' files in it..."));
            return false;

        // see if it matches the global var. if it does, use the var instead...
        if (GetUserVariableManager().Exists(_T("#wx")))
            local gvar = ReplaceMacros(_T("$(#wx)"), true);
            if (gvar.Matches(dir_nomacro))
                dir = gvar;
        WxPath = dir;
    return true;

The question is: this function call
return false.

But I do have a global variable "wx" in C::B Menu->Settings->Global variables.

When reading the source, I see that:
bool UserVariableManager::Exists(const wxString& variable) const
    if (variable.find(_T('#')) == wxString::npos)
        return false;

    wxString member(variable.AfterLast(wxT('#')).BeforeFirst(wxT('.')).BeforeFirst(wxT(')')).MakeLower());
    return !m_CfgMan->Exists(cSets + m_ActiveSet + _T('/') + member + _T("/base"));

Why there is a ! before m_CfgMan->Exists() ?
When debug into m_CfgMan->Exists(), I see that it do return true, but GetUserVariableManager().Exists() is false.

Another question is: Is user variable different from global variable? Any one can explain? Thanks.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.