Article View: borland.public.cppbuilder.internet.socket
Article #4777Re: Why access violation?
From: Steve
Date: Sat, 11 Dec 2004 12:04
Date: Sat, 11 Dec 2004 12:04
47 lines
2162 bytes
2162 bytes
Thanks, I initially tried this tnmftp *nmftp = new tnmftp(), it would not compile so I did not think that was the right way. I did not think to put null in the parens. Steve "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Steve" <sportock@mindspring.com> wrote in message >news:41ba1754$1@newsgroups.borland.com... > >> //new instance of ftp >> TNMFTP *NMFTP; > >That is not a new instance. That is merely declaring a pointer. A pointer >is not an instance. It can point to an instance, though. > >Change that line to this instead: > > TNMFTP *NMFTP = new TNMFTP(NULL); > >Then free the object when you are done with it: > > delete NMFTP; > >> It bombs on the next line with an access violation >> NMFTP->Host = ".com"; > >As well it should. You did not create an actual instance of the object yet. >Your pointer is not assigned to anything, so it points to random memory. > >> Why? It compiles fine, and runs in a >> form app, why not in a console app? > >It works in a form because you probably dropped the component onto the form >at design-time, aren't you? By doing that, the DFM system automatically >creates the object at runtime and updates the pointer to point to it. On >your console code, you have to it yourself manually. > > >Gambit > > >
Technical Details
Message-ID:
<41bae24f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41ba1754$1@newsgroups.borland.com> <41ba1d49$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,cf146df7c5a045f5 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Steve" <sportock@mindspring.com> Sender: "Steve" <sportock@mindspring.com> Reply-To: "Steve" <sportock@mindspring.com> Subject: Re: Why access violation? Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 24.178.50.100 References: <41ba1754$1@newsgroups.borland.com> <41ba1d49$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <41bae24f$1@newsgroups.borland.com> Date: 11 Dec 2004 04:04:31 -0800 X-Trace: newsgroups.borland.com 1102766671 207.105.83.66 (11 Dec 2004 04:04:31 -0800) Lines: 48 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail