Board index » delphi » Free does not work correctly. HELP

Free does not work correctly. HELP

look if you start a new project and put a single button in it and put the
following code in

procedure TForm1.Button1Click(Sender: TObject);
var
myini : TIniFile;
begin
   myini.free;
end;

The form disappears.........
Try debugging in a dll.

How can they justify that.
Major Major Bug

because if I try the following. I get an access violation

var
myini : TIniFile;
strtemp: string;
begin
try
  begin
  myini.create('c:\windows\win.inj'); { spelling mistake is on purpose}
  strtemp:=myini.readstring('IDAPI','CONFIGFILE01','ERROR');
  myini.free;
  end;
except
  begin
  myini.free;
  messagebeep(MB_OK);
end;

Why doesnt free work cleanly

 

Re:Free does not work correctly. HELP


Quote
p.ew...@gmg.com.au (Peter Ewing) wrote:
>look if you start a new project and put a single button in it and put the
>following code in
>procedure TForm1.Button1Click(Sender: TObject);
>var
>myini : TIniFile;
>begin
>   myini.free;
>end;
>The form disappears.........
>Try debugging in a dll.
>How can they justify that.
>Major Major Bug
>because if I try the following. I get an access violation
>var
>myini : TIniFile;
>strtemp: string;
>begin
>try
>  begin
>  myini.create('c:\windows\win.inj'); { spelling mistake is on purpose}

This should be:

myini := TIniFile.create('c:\windows\win.inj');

Your statement does NOT create the object, so the access violation is
natural, since myini is never allocated (and will point at a random
piece of computer).

Quote
>  strtemp:=myini.readstring('IDAPI','CONFIGFILE01','ERROR');
>  myini.free;
>  end;
>except
>  begin
>  myini.free;
>  messagebeep(MB_OK);
>end;

Hope this helps

David

David A. Schweizer
iec ProGAMMA
d.a.schwei...@gamma.rug.nl

Re:Free does not work correctly. HELP


Peter,

What you've described is not a bug in Delphi.

You can't free something you haven't created.

Your code should read something like this:

myini:=TIniFile.Create('win.inj');
strtemp:=myini.readstring...
myini.free;

Dan Doxtader

Peter Ewing <p.ew...@gmg.com.au> wrote in article
<p.ewing.171.056BB...@gmg.com.au>...

Quote
> procedure TForm1.Button1Click(Sender: TObject);
> var
> myini : TIniFile;
> begin
>    myini.free;
> end;

You haven't created the object here.

Quote

> The form disappears.........
> Try debugging in a dll.

> How can they justify that.
> Major Major Bug

> because if I try the following. I get an access violation

> var
> myini : TIniFile;
> strtemp: string;
> begin
>   myini.create('c:\windows\win.inj'); { spelling mistake is on purpose}

above line should read: myini:=TIniFile.Create('win.inj');

...

Re:Free does not work correctly. HELP


Quote
Dan Doxtader wrote:

> Peter,

> What you've described is not a bug in Delphi.

How ever free doesn't set the 'Freed' pointer to nil

try this
...
myObject.Create;
myObject.Free;
if myObject = Nil then
        myObject.Create;

this if statement will not evaluate true ...

Thankyou Borland!

Other Threads