Sign in Join

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

Mailing lists / fpc-pascal / 2001-10

OOP - What is wrong here? Please help!

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Rainer Hantsch

Hello, all!
This is a testing version of my browser - currently only a very rudimentary skeleton, but even this makes troubles...
I get the following error during compilation, but I do not understand the reason. Can you, please, have a look on that?

This here is the unit which defines the object "oBrowser". It uses oCRT because I write only telnet-applications.
--<snip>--------------------
unit browser;
{$H+}

INTERFACE
uses oCRT;
type
tListe = record
          s     : string;
	  prev,
	  next  : pointer;
         end;
pListe = ^tListe;
oBrowser = object
            public
	    constructor Init(x1,y1,x2,y2,fra,bga: byte; hdr: string);
	    destructor  Done;
	    private
	    win		:	tnWindow;	// from oCRT
	    ListStart	:	pointer;
	    Liste	:	pListe;
	    procedure Load; virtual;
	  end;
IMPLEMENTATION
//////////////////////////////////////////////////////////////////////////
constructor oBrowser.Init(x1,y1,x2,y2,fra,bga: byte; hdr: string);
begin
	// Initialisieren der Liste
	ListStart:=nil;
	Liste:=nil;
	// Laden der Daten in die Liste
	Load;
	// Öffnen des Fensters
	nMakeWindow(win, x1,y1,x2,y2,bga,fra,fra shl 4,true,left,hdr);
	win.show;
end;
//////////////////////////////////////////////////////////////////////////
destructor oBrowser.Done;
begin
	// Abbauen der Liste vom Heap
	while ListStartnil do
	begin
		Liste:=ListStart;
		ListStart:=Liste^.next;
		Liste^.s:='';			// Weil s=Ansistring, muß zuerst s auf '' gesetzt werden
		dispose(Liste);		// Freigeben des Elementes
	end;
	// Fenster schließen
	Win.done;
end;
//////////////////////////////////////////////////////////////////////////
procedure oBrowser.Load;	// Dummy-Procedure
begin
end;
//////////////////////////////////////////////////////////////////////////
begin
end.
--<snap>--------------------
This here is a main program for testing the above oBrowser. It should do here
only the following: OPEN a window, wait 6 seconds and then close the window
again...
--<snip>--------------------
// This is the main program for testing oBrowser...
program t;
{$H+}
uses oCRT, browser;
type
otest = object(oBrowser)
          procedure Load; virtual;
        end;
procedure otest.load;
begin
end;
begin
	otest.Init(1,1,80,25,white,white,'Hallo');
	delay(6000);
	otest.done;
end.
--<snap>--------------------

if I try to compile "t.pp", I get the following error:

fpc t

Free Pascal Compiler version 1.0.4 [2000/12/18] for i386 Copyright (c) 1993-2000 by Florian Klaempfl
Target OS: Linux for i386
Compiling t.pp
Compiling browser.pp
Assembling browser
t.pp(16,8) Error: Only static variables can be used in static methods or outside methods
t.pp(16,8) Error: Illegal expression
t.pp(16,8) Fatal: Syntax error, ; expected but identifier INIT found

WHY?

mfg

Ing. Rainer Hantsch

\\|// Ing. Rainer HANTSCH - Hardware + Software (o o) Forget Windoze! -- We focus on L-I-N-U-X... --oOOo-(_)-oOOo-------------------------------------------------- Ing. Rainer HANTSCH | e-Mail:
Khunngasse 21/20 | www : http://www.hantsch.co.at A-1030 Vienna | Tel. : ++43 - 1 - 7988538 0 ---------------------| Fax : ++43 - 1 - 7988538 18 ** AUSTRIA ** | Mobile: ++43 - 663 - 9194382 -----------------------------------------------------------------

Reply by email

Stefan Becker
to Rainer Hantsch

Hi Rainer,

The problem is simple!
throughout the diffiations of all the object data...

type
kkfdslk = object......
procedure .....
ect...

Now use have used correctly make the objects and methodes.....

Show quoted text 8 lines
type otest = object(oBrowser) procedure Load; virtual; end; procedure otest.load; begin end;

Okay
But, up to this point there has NEVER been an
alocation of real memory. These are ALL "type" definitions.

Wrong!

Show quoted text 7 lines
begin otest.Init(1,1,80,25,white,white,'Hallo'); delay(6000); otest.done; end.

This should read something like this:
VAR
st_x : otest; {<-- the first time memory is reserved} {or dynamik}
dy_x : ^otest; {<-- only uses a pointer of memory}

begin
 st_x.Init(1,1,80,25,white,white,'Hallo');
 delay(6000);
 st_x.done;
{or}
  dy_x:=new(dy_x,init(1,1,80,25,white,white,'Hallo'));
  delay(6000);
  dispose(dy_x,done);
end.

LUFA Speyer (EDV)
email:
tel : +49 (0)6232-629542
fax : +49 (0)6232-629544
http://www.lufa-speyer.de/

Reply by email