[fpc-pascal] "class" methods for objects
Helmut Hartl
helmut.hartl at firmos.at
Fri Jul 16 13:35:06 CEST 2010
Am 16.07.10 12:46, schrieb Michael Van Canneyt:
>> Always learning something new.
>>
> One is never too old to learn :-)
>
> Michael.
But one is always able to age faster,
while boldly going to where no man has gone
baldly before :-) (spelling intentional)
While testing with a simplified usage pattern I encountered a compiler
problem.
Should I report a bug - or am I missing something ?
helmut
--snip--
program project_static2;
{$static on}
type
Etyp=(t1,t2,t3);
function ProxyObject_IsInSubrange(const typ:Etyp):boolean;
begin
ProxyObject_IsInSubrange:=typ<=t2;
end;
type
ProxyObject=object
function IsInSubrange(const typ:Etyp):boolean;static;
end;
RealObject=object
mytyp:Etyp;
function IsInSubrange:boolean;
end;
function RealObject.IsInSubrange: boolean;
begin
IsInSubrange:=ProxyObject.IsInSubrange(mytyp); //
project1.lpr(25,15) Error: Class isn't a parent class of the current class
IsInSubrange:=ProxyObject_IsInSubrange(mytyp); //works but very ugly
(due to lots of similar code)
end;
function ProxyObject.IsInSubrange(const typ: Etyp): boolean;
begin
IsInSubrange:=typ<=t2;
end;
var o:RealObject;
begin
writeln(ProxyObject.IsInSubrange(t3));
o.mytyp:=t3;
writeln (o.IsInSubrange);
end.
--snap--
Output:
--- fpc 2.4.0:
BigMac:test helly$ /usr/local/lib/fpc/2.4.0/ppc386 project_static2.lpr
Free Pascal Compiler version 2.4.0 [2009/12/20] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Darwin for i386
Compiling project_static2.lpr
project_static2.lpr(22,29) Error: Class isn't a parent class of the
current class
Fatal: Compilation aborted
An unhandled exception occurred at $000994AD :
EAccessViolation : Access violation
$000994AD
$001264B6
$0012A57D
$0012A58E
$0012A58E
$0012A58E
$0012ADF0
$00119AD9
$00119D89
$001118E1
$00114BAA
$0011555C
$001158B2
$0011176D
$00114BAA
$001507FC
$000310F3
--- fpc 2.5.1 + debuginfo
BigMac:test helly$ /usr/local/lib/fpc/2.5.1/ppc386 project_static2.lpr
Free Pascal Compiler version 2.5.1 [2010/07/16] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Darwin for i386
Compiling project_static2.lpr
project_static2.lpr(2,2) Warning: Illegal compiler directive "$STATIC"
project_static2.lpr(22,29) Error: Class isn't a parent class of the
current class
Fatal: Compilation aborted
An unhandled exception occurred at $000B2CED :
EAccessViolation : Access violation
$000B2CED TYPECHECKPASS_INTERNAL, line 70 of
/Users/helly/pascal/fpc_trunk/compiler/pass_1.pas
$0014B006 FACTOR, line 2317 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0014EB9A SUB_EXPR, line 2772 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0014EBAB SUB_EXPR, line 2774 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0014EBAB SUB_EXPR, line 2774 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0014EBAB SUB_EXPR, line 2774 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0014F261 EXPR, line 2902 of
/Users/helly/pascal/fpc_trunk/compiler/pexpr.pas
$0013CD97 STATEMENT, line 1111 of
/Users/helly/pascal/fpc_trunk/compiler/pstatmnt.pas
$0013D0D9 STATEMENT_BLOCK, line 1219 of
/Users/helly/pascal/fpc_trunk/compiler/pstatmnt.pas
$001346EB BLOCK, line 246 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$00137B6A TCGPROCINFO__PARSE_BODY, line 1440 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$00138516 READ_PROC, line 1753 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$00138902 READ_DECLARATIONS, line 1862 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$00134519 BLOCK, line 171 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$00137B6A TCGPROCINFO__PARSE_BODY, line 1440 of
/Users/helly/pascal/fpc_trunk/compiler/psub.pas
$0017679C COMPILE, line 403 of
/Users/helly/pascal/fpc_trunk/compiler/parser.pas
$000334A3 COMPILE, line 249 of
/Users/helly/pascal/fpc_trunk/compiler/compiler.pas
More information about the fpc-pascal
mailing list