[fpc-pascal] gtree - Freeing a nil Root without error
Hi, gtree.TTree type has the following code: constructor TTree.Create; begin FRoot := nil; end; destructor TTree.Destroy; begin FRoot.Free; end; How is possible then that the following program don't raise an error when the destructor (via free) is called? program Project1; {$mode objfpc}{$H+} uses Classes, gtree; type TStrTree = specialize TTreeString; var tt: TStrTree; begin tt:=TStrTree.Create; if tt.Root = nil then WriteLn('Root is nil!'); tt.Free; end. Thanks, Daniel ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] gtree - Freeing a nil Root without error
In our previous episode, Daniel Gaspary said: gtree.TTree type has the following code: How is possible then that the following program don't raise an error when the destructor (via free) is called? Free only calls the destructor if self isn't nil. procedure TObject.Free; begin // the call via self avoids a warning if selfnil then self.destroy; end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] gtree - Freeing a nil Root without error
On Tue, Jan 7, 2014 at 6:27 PM, Marco van de Voort mar...@stack.nl wrote: Free only calls the destructor if self isn't nil. Thank you, Marco. I was searching in stl package for a Graph type. is there such type? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] gtree - Freeing a nil Root without error
On Tue, Jan 7, 2014 at 6:55 PM, Daniel Gaspary dgasp...@gmail.com wrote: Thank you, Marco. I was searching in stl package for a Graph type. is there such type? Answering to myself... I believe the Graph types exist only in Lazarus LazControls package, unit LvlGraphCtrl. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] gtree - Freeing a nil Root without error
Actually, I'm planning on redesigning gtree to be a part of larger ggraph unit. As in the data structure theory, a tree is just a graph without cycle. So I guess it should be made that way. There are a lot of graph and tree variations though, so I think I need to take some time to design before implementing. Besides, I'm a bit busy these days. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/gtree-Freeing-a-nil-Root-without-error-tp5717832p5717836.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal