On Sat, Mar 2, 2013 at 7:51 AM, Michael Van Canneyt
wrote:
>
>
> On Sat, 2 Mar 2013, Howard Page-Clark wrote:
>
>> On 02/03/13 5:45, Flávio Etrusco wrote:
>>>
>>> On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote:
(...)
>
> Also, setting Self to nil is nonsense.
>
> If you do FreeAndNil(
Sven Barth schrieb:
If you want to ensure that MyInstance is Nil you need to do it like this:
=== code begin ===
try
MyInstance := TMyClass.Create('AnNonExistentFile');
except
MyInstance := Nil;
end;
=== code end ===
When an exception occurs in Create, the assignment will never take
pl
On 02/03/13 10:51, Michael Van Canneyt wrote:
This will definitely cause a memory leak, because the FPC code does not
know that an exception occurred in the constructor (you catch it with
Except), and hence will not call the destructor.
Thanks for the correction and explanation.
Howard
--
_
On Sat, 2 Mar 2013, Howard Page-Clark wrote:
On 02/03/13 5:45, Flávio Etrusco wrote:
On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote:
Hi there,
If my class constructor looks like this:
constructor TMyClass.Create(fn: string);
begin
sl := TStringList.Create;
try
fs := TFil
On 02/03/13 5:45, Flávio Etrusco wrote:
On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote:
Hi there,
If my class constructor looks like this:
constructor TMyClass.Create(fn: string);
begin
sl := TStringList.Create;
try
fs := TFileStream.Create(fn, fmOpenRead);
except
se
On 02.03.2013 03:49, Xiangrong Fang wrote:
Hi there,
If my class constructor looks like this:
constructor TMyClass.Create(fn: string);
begin
sl := TStringList.Create;
try
fs := TFileStream.Create(fn, fmOpenRead);
except
self.Destroy;
end;
end;
No, this is a bad idea. If
On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang wrote:
> Hi there,
>
> If my class constructor looks like this:
>
> constructor TMyClass.Create(fn: string);
> begin
> sl := TStringList.Create;
> try
> fs := TFileStream.Create(fn, fmOpenRead);
> except
> self.Destroy;
> end;
> end;
Hi there,
If my class constructor looks like this:
constructor TMyClass.Create(fn: string);
begin
sl := TStringList.Create;
try
fs := TFileStream.Create(fn, fmOpenRead);
except
self.Destroy;
end;
end;
I create the objec like: MyInstance :=
TMyClass.Create('AnNonExistentFile');