Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scope issue s using TFrame

Status
Not open for further replies.

VDG

Technical User
Oct 18, 2005
43
CA
I am working on an application that has a TFrame component and as long as I access my LoadFrame function from the frame, by a popup menu, it works fine and the images load Ok.

However, if I try to load the frame from the application my private class variables are unreachable. It doesn’t matter if the variables are public or private. The error is an access violation, when I walk through the debugger, the variable nOS_Sections shows up as nOS_Sections: ???? in the watch panel.

I’m not sure what’s up.

Example:
Code:
//---------------------------------------------------------------------------
class TFrame_OSDisplay : public TFrame
{
__published:	// IDE-managed Components
    TPanel *Panel_OSDisplay;
    TPopupMenu *PopupMenu1;
    TMenuItem *EdtiOSSection1;
    TSaveDialog *SaveDialog1;
    void __fastcall EdtiOSSection1Click(TObject *Sender);
private:	// User declarations
    int         nOS_Sections;
    OS_Section  *Track_OS[MAX_BLOCKS];
public:		// User declarations
    __fastcall TFrame_OSDisplay(TComponent* Owner);
    void __fastcall DeleteOSDisplay(void);
    void __fastcall LoadTerritory(void);
    void __fastcall SaveTerritory(void);
};
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TFrame_OSDisplay::LoadTerritory(void)
{
    int             nTemp,
                    nX;

    String          sFileName,
                    sString;

    TStringList     *slBlocks;

    sFileName = Form_Main->sesSession.terTerritory.sTerritoryFileName;
    if(sFileName== "")    {
        Application->MessageBox("Session not loaded!",
                                "Territory Frame",
                                MB_ICONWARNING | MB_OK);
    }
    else    {
        slBlocks = new TStringList;
        slBlocks->LoadFromFile(sFileName);
        while(slBlocks->Count > 0)  {
            if(slBlocks->Strings[0].Pos("[MAX BLOCK] ") > 0)    {
                nTemp = slBlocks->Strings[0].Length() - 12;
                sString = slBlocks->Strings[0].SubString(13, nTemp);
            }
            else if(slBlocks->Strings[0].Pos("[BLOCK] ") > 0)    {
                nTemp = slBlocks->Strings[0].Length() - 8;
                sString = slBlocks->Strings[0].SubString(9, nTemp);
                nOS_Sections = sString.ToInt();
                if(((nOS_Sections + 1) * 100) > Panel_OSDisplay->Width){
                    Panel_OSDisplay->Width = (nOS_Sections + 1) * 100;
                }
                Track_OS[nOS_Sections] = new OS_Section(Panel_OSDisplay, nOS_Sections);
            }
            slBlocks->Delete(0);
        }
        delete slBlocks;
        nOS_Sections++;
    }
}
//---------------------------------------------------------------------------

//  This works!
//---------------------------------------------------------------------------
void __fastcall TFrame_OSDisplay::EdtiOSSection1Click(TObject *Sender)
{
        LoadTerritory();
}
//---------------------------------------------------------------------------

// This Dosen’t!
//---------------------------------------------------------------------------
void __fastcall TForm_Main::Open1Click(TObject *Sender)
{
    Frame_OSDisplay->LoadTerritory();
}
//---------------------------------------------------------------------------

Any help will be greatly appreciated.

Thanks in advance.

Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top