Re: newbie: deactivate query before freeing?
- From: "swansnow" <schultz@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: 28 Sep 2005 16:37:55 -0700
How about:
myQuery := TQuery.create(nil);
try
myQuery.sql.text := 'select * from blah';
...
finally
freeAndNil(myQuery);
end;
See if I'm right:
This way, if the Create failed, then myQuery is an invalid reference,
and trying to use it will result in an exception, in which case, it
will be assigned nil, but the exception will still be thrown. If the
Create succeeded then the query will execute and so forth. If an
exception occurs in the "try" code, the reference will be freed, and
then the exception will be thrown. If no exceptions are generated, the
reference still gets freed, and everything's fine.
In addition you're saying that the following code is ok:
myQuery := nil;
freeAndNil(myQuery);
But the following code isn't ok?
myQuery := nil;
myQuery.free;
Do I have it right?
-Corinna
.
- Follow-Ups:
- Re: newbie: deactivate query before freeing?
- From: Maarten Wiltink
- Re: newbie: deactivate query before freeing?
- From: Maarten Wiltink
- Re: newbie: deactivate query before freeing?
- From: Maarten Wiltink
- Re: newbie: deactivate query before freeing?
- References:
- newbie: deactivate query before freeing?
- From: swansnow
- Re: newbie: deactivate query before freeing?
- From: Maarten Wiltink
- newbie: deactivate query before freeing?
- Prev by Date: Re: newbie: deactivate query before freeing?
- Next by Date: Re: newbie: deactivate query before freeing?
- Previous by thread: Re: newbie: deactivate query before freeing?
- Next by thread: Re: newbie: deactivate query before freeing?
- Index(es):
Relevant Pages
|
|