[fpc-pascal]FPC Error! :(

Matt D. Emson matt at Diplomat.co.uk
Fri Feb 14 11:44:23 CET 2003


James,

This is not a personal attack, just some comments about style and some
shortcomings of the code you present.


//You should alter this a bit. It's a very strange mix between
TurboPascal and Delphi syntax....

>    TNicks = class(TObject) //Delphi style syntax

Public // the default is visibility is 'Published'

>       constructor init(tmpNick: String); //TP Stlyle syntax

Constructor Create(tmpNick: String); virtual; //always a good move

>       destructor done; //TP Stlyle syntax.. Very bad. FreeInstance
will 
                         //not be called unless 'inherited Destroy' is
called 
                         //from this routine

Destructor Destroy; override; //otherwise the memory manager will not
deallocate the class properly

>       private
...
>    end;

>    PNicks = ^TNicks; //overkill

You do not need this!! A class instance is already a reference (read
'typed' 'pointer') to an object. For example.. Declare a Tlist, add a
Tobject to it.. You need not typecast. It *is* a pointer. There are no
stack objects in Delphi style syntax. The classes are just automagically
dereferenced.

...

> procedure TChanServ.doLIST(source: String; data: String);
> var
>    tokens:  TTokenizer;
>    channel: String;
>    what: String;
>    index:   Integer;
>    I:       Integer;
> begin
     tokens := Ttokenizer.Create(data);
     try
>      channel := tokens.nextToken;
>      what := tokens.nextToken;
     finally
       tokens.free;
     end;

Try ... Finally is your friend. Embrase it. Learn to protect your
resourses! ;-)

...

You'll get horrible memory leaks if you don't be carefull using classes
with the object syntax as you have.

NB. If I have missed something about the FPC non delphi/ObjFPC
implementation of the class (as opposed to the object) I rightly point
out that either the Delphi syntax or the TP syntax is correct, by
definition. Both are distinct, and advocating the mixture of the two is
very bad. I think I've said this before. Sorry for repeating myself.
IIRC we discussesd this along with the merits of the extended object
pascal spec (the one our friend Amto Tichwa recently also mentioned),
but I forget what the answer was then. 

Matt






More information about the fpc-pascal mailing list