[comp.sys.mac.programmer] Methods overriding global functions

ml27192@uxa.cso.uiuc.edu (lanett mark) (12/30/90)

I'm writing a program using MacApp that for various reasons uses the generic
pascal i/o routines like open/close. When I try to call close from a method
of a TDocument class the compiler flags an error. The problem is that TDoc
_already_ has a method called close, with no arguments, and the compiler is
trying to use that one instead of the generic close. I am not using Self, 
either. I could make the file reference variable a global, and call a special
globasl function to close it (which would not be in TDoc), but I'd like to
know if there's any way to avoid this sort of thing in the first place. For that
matter, why the h*** did Apple give a method a name that would cause this kind
of conflict. Yes, I know you don't normally use standard pascal i/o, but I
don't really want to rewrite the existing code that does it.

Example: I know this won't work. The trouble is it doesn't compile, though it
should. How do you get the compiler to use the regular close?

program sample (input, output);
 
type
	foo = object
		procedure run;
		procedure close;
	end;
 
procedure foo.run;
 
	var z: text;
	
	begin
		close (z); (* *** Compiler wants to use foo.close (no args) *)
	end;
 
procedure foo.close;
 
	begin
		writeln ('closing');
	end;
 
var a: foo;
	
begin
	new (a);
	a.run;
end.

Thanks much,
Mark Lanett, ml27192@uxa.cs.uiuc.edu

lanett.mark@f20.n226.z1.FIDONET.ORG (lanett mark) (12/30/90)

Reply-To: ml27192@uxa.cso.uiuc.edu

I'm writing a program using MacApp that for various reasons uses the generic
pascal i/o routines like open/close. When I try to call close from a method
of a TDocument class the compiler flags an error. The problem is that TDoc
_already_ has a method called close, with no arguments, and the compiler is
trying to use that one instead of the generic close. I am not using Self, 
either. I could make the file reference variable a global, and call a special
globasl function to close it (which would not be in TDoc), but I'd like to
know if there's any way to avoid this sort of thing in the first place. For
that
matter, why the h*** did Apple give a method a name that would cause this kind
of conflict. Yes, I know you don't normally use standard pascal i/o, but I
don't really want to rewrite the existing code that does it.

Example: I know this won't work. The trouble is it doesn't compile, though it
should. How do you get the compiler to use the regular close?

program sample (input, output);
 
type
        foo = object
                procedure run;
                procedure close;
        end;
 
procedure foo.run;
 
        var z: text;
        
        begin
                close (z); (* *** Compiler wants to use foo.close (no args)
*)
        end;
 
procedure foo.close;
 
        begin
                writeln ('closing');
        end;
 
var a: foo;
        
begin
        new (a);
        a.run;
end.

Thanks much,
Mark Lanett, ml27192@uxa.cs.uiuc.edu

 + Organization: University of Illinois at Urbana

--  
lanett mark - via FidoNet node 1:105/14
    UUCP: ...!{uunet!glacier, ..reed.bitnet}!busker!226!20!lanett.mark
INTERNET: lanett.mark@f20.n226.z1.FIDONET.ORG

daven@svc.portal.com (12/31/90)

In article <1990Dec30.044453.29640@ux1.cso.uiuc.edu> ml27192@uxa.cso.uiuc.edu (lanett mark) writes:
>I'm writing a program using MacApp that for various reasons uses the generic
>pascal i/o routines like open/close. When I try to call close from a method
>of a TDocument class the compiler flags an error. The problem is that TDoc
>_already_ has a method called close, with no arguments, and the compiler is
>trying to use that one instead of the generic close. I am not using Self, 
>either.

I can't think of any "slight of hand" that will make the Pascal compilier do
what you want without forcing something to change it's name.

Using a global routine that calls Close would be the easiest thing to do.
I serious believe the MacApp team assumed that most people would be calling
the Mac's FSClose routine instead of the Pacal I/O Close routine.

-- 
-------------------------------------------------------------------------------
   Dave Newman              |  daven@svc.portal.com        |  AppleLink: D0025
   Sofware Ventures Corp.   |  AOL: MicroPhone             |  CIS: 76004,2161
   Berkeley, CA  94705      |  WELL: tinman@well.sf.ca.us  |  (415) 644-3232

Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (01/01/91)

lanett mark writes in a message to All

LM>  close (z); (* *** Compiler wants to use foo.close (no args

Simple (I think):

procedure myClose(var z:text);
begin
     close(z);
end;


That should work, as long as "myClose" isn't another method of foo (or any other
object, for that matter).

Lawson
 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English
Internet: Lawson.English@p88.f15.n300.z1.fidonet.org