Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2000-06

Stange error message

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Weustink

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 get this message on the line of begin, for each function which declares a local var. I can't see why or what this message means.

procedure TContolSelection.Clear;
var
   n:  Integer;
begin <-- error is pointing here
...
end;

Marc

Reply by email

Marc Weustink
to Marc Weustink
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

Reply by email

Marc Weustink
to Robert Scott Horning: I'm kinda curious about this construct. In Delphi, when you declare something like: type…

+ From: Robert Scott Horning

+ 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.

Nope. A forward declaration is

 type
    TMyControl = class;

[snip]

+ 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).

Thats what i wanted.

But the funny thing is the fpc compiler doesnt complain about this. It looks like it treats your whole implementation as classmembers, and complains that you can't create vars.

Im working on a example to verify what I think.

Marc

Reply by email

Robert Scott Horning
to Marc Weustink: I found the error. In my implementation section I declared the following type TMyControl…
Marc Weustink wrote 26 lines
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:

Reply by email

Marc Weustink
to Robert Scott Horning
Michael Van Canneyt wrote 21 lines
> Marc Weustink wrote: > > > > 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; No it does not. The following compiles fine: unit testc; interface Type TMyClass = Class (Tobject); Implementation end.

........

Ofcourse does this work. Thats the reason why I found it a strange error message. Try the following code.

Marc

-----------------------------------

unit testclass;
{$mode objfpc}
interface
uses
   Classes;
type
   TMyClass = class(TObject)
     procedure MyProc;
   end;
implementation
type
   TMyOtherClass = class(TPersistent);
procedure TMyClass.MyProc;
var
   MyImportantVar: Integer;
begin
end;
end.

-----------------------------------

marc:~/fpc/lazarus/test$ ppc386 testclass.pp
Target OS: Linux for i386
Compiling testclass.pp
testclass.pp(23,1) Error: Symbol can't be published, can be only a class testclass.pp(27) Fatal: There were 1 errors compiling module, stopping

Reply by email

Marc Weustink
to Marc Weustink: Try to compile: program testclass; {$mode objfpc} uses Classes; type TMyClass =…
Peter Vreman wrote
>program testclass; Fixed

Allmost, this one was harder to pinpoint

Try the following example.
NOTE 1: Both items of MyRec are important. (one item seems ok) NOTE 2: After a second compile the problem is gone.

------------------------------------

program testclass;
{$mode objfpc}
uses
   MyUnit;
type
   TMyRec = record
     MyItem: Integer;
     MyOtherItem: Integer;
   end;
begin
end.

------------------------------------

unit MyUnit;
{$mode objfpc}
interface
uses
   Classes;
implementation
type
   TMyClass = class(TPersistent);
end.

------------------------------------

marc:~/fpc/lazarus/test$ rm *.o
marc:~/fpc/lazarus/test$ ppc386 testclass.pp
Target OS: Linux for i386
Compiling testclass.pp
Compiling myunit.pp
Assembling (pipe) myunit.s
testclass.pp(12,3) Error: Symbol can't be published, can be only a class testclass.pp(17) Fatal: There were 1 errors compiling module, stopping marc:~/fpc/lazarus/test$

Reply by email

Michael Van Canneyt
to Robert Scott Horning: I'm kinda curious about this construct. In Delphi, when you declare something like: type…
Robert Scott Horning wrote 26 lines
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;

No it does not. The following compiles fine:

unit testc;
interface
Type
  TMyClass = Class (Tobject);
Implementation
end.

If you look in sysutils, you will see many such declarations for exceptions.

Show quoted text 11 lines
> > 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.

No, it is not. The above is a _complete_ class definition.

The following is a forward class reference:

  TMyControl = Class;

Michael.

Reply by email