BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

access violation when accessing public class variable from w

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Apr 20, 2007 11:44 pm    Post subject: access violation when accessing public class variable from w Reply with quote



I'm writing a component that will allow the user to "snap" a window to
the side of an MDI window, which will create a panel that will
represent the auto-hide window. The problem is, no matter what I do
to try and store a pointer to the form in my TDockingPanel class, I
get an access violation when attempting to access it from within the
class. However, when I access the pointer from outside the class, I
get no access violation, and everything is correct! Here's the code:

class PACKAGE TDockingPanel : public TPaintBox
{
private:
TNotifyEvent FOnMouseEnter;
TNotifyEvent FOnMouseLeave;
AnsiString FCaption;
bool MouseIsOver;
bool Down;
TTimer *Timer;
AnsiString FPanelForm;
void __fastcall CustomPaint(TObject *Sender);
void __fastcall ClickEvent(TObject *Sender);
void __fastcall TimerEvent(TObject *Sender);
void __fastcall MouseEnter(TObject *Sender);
void __fastcall MouseLeave(TObject *Sender);
void __fastcall WriteCaption(AnsiString c);
void __fastcall GrowRect(TRect &R, int pixels);
HFONT __fastcall CreateVerticalFont();
void __fastcall CenterText(AnsiString text);
void __fastcall RevealForm();
void __fastcall HideForm();
protected:
void __fastcall WndProc(TMessage &Message);
public:
__fastcall TDockingPanel(TComponent* Owner);
TForm *f; // the form associated with this TDockingPanel
__published:
__property AnsiString Caption = {read = FCaption, write =
WriteCaption};
__property TNotifyEvent OnMouseEnter = {read = FOnMouseEnter,
write = FOnMouseEnter};
__property TNotifyEvent OnMouseLeave = {read = FOnMouseLeave,
write = FOnMouseLeave};
};

// an example member function which gives an access violation:

void __fastcall TDockingPanel::RevealForm()
{
if (f)
{
ShowMessage(f->Caption);
}
}

// a simplified example which does NOT give an access violation

void __fastcall TForm2::Start1Click(TObject *Sender)
{
DockingPanel1->f = Form1;
ShowMessage(DockingPanel1->f->Caption);
}

How could this be? I'm using BCB 5. The component is included in
package dclusr50. It doesn't make much sense. By the way,
TDockingPanel::RevealForm() is generated on a MouseEnter event, which
I trigger AFTER the form's address has been assigned to f. CodeGuard
says I have an access overrun in Start1Click. I don't know what this
means or how to fix it. I've tried making f a property of
TDockingPanel, but that didn't work either.

TIA.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.