Sign in Join

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

Mailing lists / fpc-pascal / 2008-01

Re: problem with interface (OOP not widget)

16 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt
to Bee: I got problem with the code below. --->8--- begin code --->8--- program test_intf_query;…
Bee wrote 62 lines
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

You have
plftOraClob, plftOraClob

2 times the same element. This is not allowed.

Michael.

Bee

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:

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

Bee
to Bee
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. :(

If it is a bug of FPC, I'll file it to Mantis ASAP. Just to make sure it's not my fault in the first place. :-D

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

Bee
to Bee
Arrggghhhh... what a stupid mistake! How can I didn't notice that?! It should be plftOraClob, plftOraBlob (clob and blob)! Thank you, Michael! Thank you again for the ultra fast response! :-D

FYI, the fatal internal error still persist. :)

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

Bee
to Bee: Arrggghhhh... what a stupid mistake! How can I didn't notice that?! It should be…
Arrggghhhh... what a stupid mistake! How can I didn't notice that?! It should be plftOraClob, plftOraBlob (clob and blob)! Thank you, Michael! Thank you again for the ultra fast response! :-D

I must slipped my fingers and eyes during conversion to FPC. I saw the code in Delphi doesn't have the mistake. How did I do that? I feel so silly. :-D

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

Giuliano Colla
to Bee: Problem still persists. :( -Bee- has Bee.ography at: http://beeography.wordpress.com

Bee ha scritto:

Show quoted text 6 lines
> Hi Bee, perhaps you could try using {$MODE Delphi} instead of {$MODE > OBJFPC} since you seem to want Delphi compatibility. Problem still persists. :( -Bee-

FWIW. I've met from time to time a Fatal Internal Error with some number which might match yours, in perfectly clean code, which used to compile flawlessly (both when building Lazarus, or building my applications). It was happening with pfc 2.0.4, it happens now with fpc 2.2.0. With a given release of Lazarus it happens quite frequently, with the next much less frequently, at random. I didn't report it, because I was unable to create a reproducible pattern. In my case, just launching again the compilation (one or two times) without touching anything else fixed the problem. A variable not properly initialized somewhere in fpc? I stopped worrying and when the error pops up I just press F9 again, and it works.
Did you try such a brute force approach?

Giuliano

Giuliano Colla Whenever people agree with me, I always feel I must be wrong (O. Wilde)
JoshyFun
to Bee: http://bugs.freepascal.org/view.php?id=10684 Is there any feasible workaround for this…

Hello Bee,

you wrote
> So, may I made a conclusion that this is a bug?

B> http://bugs.freepascal.org/view.php?id=10684

B> Is there any feasible workaround for this before the bug is fixed? TIA.

I wrote some small changes to your code and the bug only raises when calling convention is cdecl and optional parameter default value is set, but mostly related to "cdecl" and interfaces because as I remove the "cdecl" everything seens to compile fine in all situations, meanwhile removing optional parameter can also rise the "bug" if I perform some type conversions "brute forced".

To workaround I wrote it in this way, adding a new wrapper function:

----------------
function QuerySimple2(const OnChange: TNotifyEvent): ISimple; cdecl;
begin
  Result :=TSimple.Create;
end;
function QuerySimple(const OnChange: TNotifyEvent =nil): ISimple;
begin
  Result :=QuerySimple2(OnChange);
end;
----------------

It is not very elegant, I know :)

Best regards, JoshyFun
Bee
to Bee: I got problem with the code below. --->8--- begin code --->8--- program test_intf_query;…

http://bugs.freepascal.org/view.php?id=10684

Hints? TIA.

I'm currently using a not too elegant workaround to solve this problem. With some IFDEFs because the workaround is for FPC only.

Nobody seems interested to this bug since there's no response for this issue in the mantis. I wonder because IMO it's some kind of basic operation for interface. Or aren't there much pascal developers that using this technique? Any other better technique for this? TIA.

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

Jonas Maebe
to Bee
Bee wrote 6 lines
http://bugs.freepascal.org/view.php?id=10684 > Hints? TIA. I'm currently using a not too elegant workaround to solve this problem. With some IFDEFs because the workaround is for FPC only.

There is no support for passing nil as a constant to a "procedure of object" parameter of a cdecl procedure at this time. You can work around it by using two overloads (one with a tnotify parameter, one without). That should work both in FPC and in Delphi.

Jonas

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote 13 lines
On 12 Mar 2008, at 05:41, Bee wrote: > http://bugs.freepascal.org/view.php?id=10684 > >> Hints? TIA. > > I'm currently using a not too elegant workaround to solve this > problem. With some IFDEFs because the workaround is for FPC only. There is no support for passing nil as a constant to a "procedure of object" parameter of a cdecl procedure at this time. You can work around it by using two overloads (one with a tnotify parameter, one without). That should work both in FPC and in Delphi.

Actually, this is more or less the same as what JoshyFun suggested earlier.

Jonas