[fpc-pascal] problem with interface (OOP not widget)
Bee
bisma at brawijaya.ac.id
Wed Jan 23 09:13:31 CET 2008
Hi all,
I got problem with the code below.
--->8--- begin code --->8---
program test_intf_query;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
uses
Classes;
type
TPLFieldType = (plftUnknown, plftString, plftSmallint, plftInteger,
plftWord, plftBoolean, plftFloat, plftCurrency, plftBCD, plftDate,
plftTime, plftDateTime, plftBytes, plftVarBytes, plftAutoInc,
plftBlob, plftMemo, plftGraphic, plftFmtMemo, plftParadoxOle,
plftDBaseOle, plftTypedBinary, plftCursor, plftFixedChar,
plftWideString, plftLargeint, plftADT, plftArray, plftReference,
plftDataSet, plftOraBlob, plftOraClob, plftVariant, plftInterface,
plftIDispatch, plftGuid, plftTimeStamp, plftFMTBcd,
plftFixedWideChar, plftWideMemo, plftOraTimeStamp, plftOraInterval);
ISimple = interface
['{24811FF3-4F01-4601-AC5C-22A5B5D46928}']
function ShowSomething: Integer; cdecl;
function GetIsBlob: Boolean; cdecl;
end;
TSimple = class(TInterfacedObject, ISimple)
private
FDataType: TPLFieldType;
protected
{ ISimple implementation }
function ShowSomething: Integer; cdecl;
function GetIsBlob: Boolean; cdecl;
end;
{ query ISimple }
function QuerySimple(const OnChange: TNotifyEvent = nil): ISimple;
cdecl;
begin
Result := TSimple.Create;
end;
{*** TSimple ***}
function TSimple.ShowSomething: Integer; cdecl;
begin
Writeln('Message from ISimple');
Result := 0;
end;
function TSimple.GetIsBlob: Boolean; cdecl;
begin
Result := FDataType in [
plftBytes, plftVarBytes, plftBlob, plftMemo, plftGraphic,
plftFmtMemo, plftParadoxOle, plftDBaseOle, plftTypedBinary,
plftOraClob, plftOraClob, plftWideMemo
];
end;
{*** main program ***}
var
FSimple: ISimple;
begin
FSimple := QuerySimple(nil);
//FSimple := TSimple.Create;
FSimple.ShowSomething;
end.
--->8--- end code --->8---
FPC failed to compile it. The compiler complained with this message:
test_intf_query.pas(56,26) Error: range check error in set constructor
or duplicate set element
With wonder, I commented line 56. Then the compiler complained with this
message:
test_intf_query.pas(66,14) Fatal: Internal error 200408162
Weird. So, I commented line 66 and uncommented line 67 (just to make it
compilable). It compiled fine. But when it's executed, it ended up with
AV. Here's the output:
bee at simba:~/Programs$ ./test_intf_query
Message from ISimple
An unhandled exception occurred at $0804816C :
EAccessViolation : Access violation
$0804816C
I'm using FPC 2.2.0, 2.2.1, and 2.3.1 on Ubuntu Gutsy i386. I thought it
was the problem with FPC for Linux, so I tried it with FPC 2.2.0 on
Windows (on exact machine). But, same errors persist on all FPC versions. :(
IMHO, the above code (before modifications to make it compilable) should
be fine. I can't see nothing wrong with it. To make sure, I compiled the
code using Delphi 7 and Turbo Delphi Explorer. Both Delphi compiled fine
and the executable output run without problem.
The actual program actually much bigger than the above, it's a part of a
big framework I've been working on. I cut it and made much simpler to
isolate the problem. FYI, the framework itself initially written using
Delphi 7 and works well. Now, I'm trying to port it to FPC.
Hints? TIA.
-Bee-
has Bee.ography at:
http://beeography.wordpress.com
More information about the fpc-pascal
mailing list