Difference between revisions of "Talk:Lazarus Tdbf Tutorial"
From Free Pascal wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
The following code | The following code | ||
<code> | <code> | ||
− | var | + | var |
− | + | MyDbf: TDbf; | |
− | begin | + | begin |
− | + | try | |
− | + | MyDbf := TDbf.Create(nil); | |
− | + | { use relative path to "data" directory } | |
− | + | // etc .. | |
− | + | MyDbf.Close; | |
− | + | finally | |
− | + | MyDbf.Free; | |
− | + | end; | |
− | end; | + | end; |
</code> | </code> | ||
should have the Create statement outsite of the try .. finally construct. Because when something goes wrong with the creation what has been created will be automatically freed. (At least this way it is in Delphi) | should have the Create statement outsite of the try .. finally construct. Because when something goes wrong with the creation what has been created will be automatically freed. (At least this way it is in Delphi) | ||
So I would advise to change to code to | So I would advise to change to code to | ||
<code> | <code> | ||
− | var | + | var |
− | + | MyDbf: TDbf; | |
− | begin | + | begin |
− | + | MyDbf := TDbf.Create(nil); | |
− | + | try | |
− | + | { use relative path to "data" directory } | |
− | + | //etc. | |
− | |||
</code> | </code> |
Revision as of 23:08, 23 March 2005
The following code
var
MyDbf: TDbf;
begin
try
MyDbf := TDbf.Create(nil);
{ use relative path to "data" directory }
// etc ..
MyDbf.Close;
finally
MyDbf.Free;
end;
end;
should have the Create statement outsite of the try .. finally construct. Because when something goes wrong with the creation what has been created will be automatically freed. (At least this way it is in Delphi)
So I would advise to change to code to
var
MyDbf: TDbf;
begin
MyDbf := TDbf.Create(nil);
try
{ use relative path to "data" directory }
//etc.