[lazarus] Stange error message

Robert Scott Horning roberth at ise-tlx.com
Thu Jun 22 10:45:54 EDT 2000


Marc Weustink wrote:

> At 01:50 22-06-2000 +0200, Marc Weustink wrote:
> >When compileing my new selection stuff I get the following error:
> >
> >controlselection.pp(140,1) Error: Symbol can't be published, can be only a
> >class
>
> I found the error.
>
> In my implementation section I declared the following
>
> type
>    TMyControl = class(TControl);
>
> const
>    blah....
>
> constructor.... etc.... all implementation stuff
>
> Unlike Delphi, FPC doesn't like this, it wants an end statement after a
> class. It should be declared as:
>
> type
>    TMyControl = class(TControl)
>    end;
>
> Marc

I'm kinda curious about this construct.  In Delphi, when you declare something
like:

type
   TMyControl = class(TControl);

this is a forward class reference, so you can use a reference to a class that
hasn't been defined yet.  I've used this a few times when I have some circular
class references within the same unit.  Normally it is expected to have another
definition also appear later in the unit (for a proper forward reference), but
I'm sure that the Object Pascal compiler doesn't get too excited if that
forward reference hasn't been fully defined.

You can also accomplish this behavior with circular unit references, but that
is simply another way to accomplish the same thing.

One of the reasons for this is the exception behavior of Delphi, where it is
VERY common to simply define a class hierarchy for a class of exception errors
such as the following:

type
   EGTK_Error = class (Exception);
   EGTK_Menu_Error = class (EGTK_Error);
   EGTK_Handle_Error = class (EGTK_Error);
   {... (you can kinda get the idea here)...}

All of these objects have all of the properties and methods of the Exception
class (which is a TObject decedent), but there is no need for defining any
additional properties or methods (even though you COULD if you really wanted
to).

The point is that you can trap for errors of a particular class (such as the
EGTK_Error class and descendants as demonstrated above), and have control over
what throws an exception in a try..except block:

try
   MyCoolFunction(WithSillyParameter);
except
   On EGTK_Error do GTK_Error_Handler;
end;

In addition, I think the Borland programmers were a little bit lazy and decided
to rewrite the compiler a bit rather than having to put in the end statement
for every class, like I've demonstrated above.

--
Robert Scott Horning
Trans-Lux West
1651 North 1000 West
Logan, Utah  84321
Phone: (435) 716-8696
FAX: (435) 752-8513
E-mail:  roberth at ise-tlx.com







More information about the Lazarus mailing list