Article View: borland.public.cppbuilder.internet.socket
Article #4775Re: Why access violation?
From: Remy Lebeau (TeamB)
Date: Fri, 10 Dec 2004 22:04
Date: Fri, 10 Dec 2004 22:04
34 lines
1937 bytes
1937 bytes
"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:
<41ba1d49$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!ecngs!feeder.ecngs.de!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41ba1754$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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <41ba1754$1@newsgroups.borland.com> Subject: Re: Why access violation? Date: Fri, 10 Dec 2004 14:04:14 -0800 Lines: 37 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <41ba1d49$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1102716233 68.69.17.41 (10 Dec 2004 14:03:53 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!ecngs!feeder.ecngs.de!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail