Delphi
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists Delphi

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old May 7th, 2008, 05:31 PM
Rob Kennedy
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
edit1.create

David Smith wrote:
I usually follow what every example in Delphi manual does. There are
certain cases where freeAndNil can cause an access violation:

Free;
:= nil;

In what way do those two lines make FreeAndNil cause an access violation?

--
Rob

Reply With Quote
  #2  
Old May 7th, 2008, 05:31 PM
Doug Hale
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
edit1.create

If does not actually point to a valid object instance,
Free will cause an access violation.


For example:
Free;
Free;
The second Free will fault.

Doug

Rob Kennedy wrote:
David Smith wrote:

>I usually follow what every example in Delphi manual does. There are
>certain cases where freeAndNil can cause an access violation:
>>

>Free;
>:= nil;
>
>

In what way do those two lines make FreeAndNil cause an access violation?
>
>

Reply With Quote
  #3  
Old May 7th, 2008, 09:31 PM
Rob Kennedy
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
edit1.create

(Top-posting fixed.)
Doug Hale wrote:
Rob Kennedy wrote:
>David Smith wrote:

I usually follow what every example in Delphi manual does. There are
certain cases where freeAndNil can cause an access violation:

Free;
:= nil;
>>

>In what way do those two lines make FreeAndNil cause an access violation?
>

If does not actually point to a valid object instance,
Free will cause an access violation.

For example:
Free;
Free;
The second Free will fault.

course.

Am I to understand that you're really not making any statement at all
about FreeAndNil? You haven't shown any examples of calling FreeAndNil,
and you haven't shown anything that would cause exceptions in FreeAndNil
that wouldn't also occur without FreeAndNil.

Your original statement made it sound like there are ways to cause
access violations in FreeAndNil that wouldn't occur in ordinary code,
and the colon at the end of your statement introduced those two lines as
an example of such code.

There _are_ ways to cause FreeAndNil to fail that wouldn't fail
otherwise, but none of the code you've shown demonstrates that.

--
Rob

Reply With Quote
  #4  
Old May 7th, 2008, 11:11 PM
Rob Kennedy
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
edit1.create

Rob Kennedy wrote:
(Top-posting fixed.)
Doug Hale wrote:
>Rob Kennedy wrote:

David Smith wrote:
I usually follow what every example in Delphi manual does. There are
certain cases where freeAndNil can cause an access violation:

[]

Your original statement made it sound like []

Sorry. I thought Doug's reply was actually coming from David.

--
Rob

Reply With Quote
  #5  
Old May 7th, 2008, 11:11 PM
Doug Hale
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
edit1.create

I have never used FreeAndNil but have always thought that it checks the
pointer before calling free.
IT DES NT - I looked at the code! (at least in D7).

Where ever
Free;
:= nil;
would cause an exception, so would
FreeAndNil();
And it is not " " (not an issue for me - the issue for me
is why remember FreeAndNil when Free; := nil; is the same).


Doug


Rob Kennedy wrote:
(Top-posting fixed.)
Doug Hale wrote:

>Rob Kennedy wrote:
>

David Smith wrote:

I usually follow what every example in Delphi manual does. There are
certain cases where freeAndNil can cause an access violation:

Free;
:= nil;

In what way do those two lines make FreeAndNil cause an access violation?

>If does not actually point to a valid object instance,
>Free will cause an access violation.
>>

>For example:
>Free;
>Free;
>The second Free will fault.
>
>

course.
>

Am I to understand that you're really not making any statement at all
about FreeAndNil? You haven't shown any examples of calling FreeAndNil,
and you haven't shown anything that would cause exceptions in FreeAndNil
that wouldn't also occur without FreeAndNil.
>

Your original statement made it sound like there are ways to cause
access violations in FreeAndNil that wouldn't occur in ordinary code,
and the colon at the end of your statement introduced those two lines as
an example of such code.
>

There _are_ ways to cause FreeAndNil to fail that wouldn't fail
otherwise, but none of the code you've shown demonstrates that.
>
>

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists Delphi > edit1.create


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway