Forum > General
IInterface issues, compiler can't find members at compile time. This is GDIPLUS
jamie:
I finished an old pet project of making a very common unit floating around for GDIPLUS to work with older fpc.
The compiler in question is 3.0.4. 64bit, windows 10.
I've done IInterface objects before and they worked find but this GDIPLUS or the compiler has a problem with something.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var I:TGDiPlusStartUpInPut; Token:ULong; G:TGPGraphics; P:TGPPen; C:TGPCOlor; S:TGPStatus;begin I.Intialize; S:=GDiPlusStartUP(Token,@I,Nil); G:=TGPGraphics.DCCreate(Canvas.Handle); P:=TGPPen.Create(TGPCOlor.BurlyWood,2); G.DrawLine(P,0,0,200,100); //<<<<<< Compiler can't find any members of the Interface. P.Free; G.Free; GDIPlusShutdown(Token);end;
The code above works basically because up to that line I pointed out, it's calling non interface members.
but when it gets to the DRAWLINE or any interface member of G, the graphics interface, the compiler has gone brain dead.
unit1.pas(46,5) Error: identifier idents no member "DrawLine"
or any member that happens to be an interface method.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure DrawLine(const Pen: IGPPen; const Pt1, Pt2: TGPPointF); overload; procedure DrawLine(const Pen: IGPPen; const X1, Y1, X2, Y2: Single); overload; procedure DrawLine(const Pen: IGPPen; const Pt1, Pt2: TGPPoint); overload; procedure DrawLine(const Pen: IGPPen; const X1, Y1, X2, Y2: Integer); overload;
As you can see, there are plenty of DrawLine methods there.
Does anyone know why the compiler can't find these methods at compile time?
EDIT:
Attached is a project and I hope the GDIPLUS came with it.
WooBean:
It may help?
This demo is not following environment described by jamie but may point at the real culprit.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project;{$mode objFPC}function aa(const a:{int64}integer):boolean; overload;begin Result:=a>0;end;function aa(const a:single):boolean; overload;begin Result:=a>0;end; begin writeln(aa(9999999999)); //project.lpr(13,11) Error: Can't determine which overloaded function to call ReadLn;end.
Maybe const parameter values (X1, Y1, X2, Y2) passed to
procedure DrawLine(const Pen: IGPPen; const X1, Y1, X2, Y2: Single)
or
procedure DrawLine(const Pen: IGPPen; const X1, Y1, X2, Y2: Integer)
are neither integer nor single?
Try
G.DrawLine(P,integer(0),integer(0),integer(200),integer(100));
jamie:
If I access those members within the same unit, "GDIPLUS", then there is no complaint.
But it's not liking the idea of jumping unit boundaries.
The Code Tools have no issues locating any of those members while editing.
As for the Overload problem, I did have that issue with the constructors, because it couldn't figure out which overload to use. I renamed the problem constructor from CREATE(DC:HDC) to DCCreate(DC:HDC); which solved the problem there.
I will try casting but I don't think that is the issue because I am not getting that message that it can't decide which overload to use, it just can't find any of the INTERFACE members of the class but non-interface members the compiler can see from other units.
EDIT:
Casting the constants does not have any effect on the compiler locating the members of the interface.
jamie:
It seems for whatever reason there is a PRIVATE field marker at the start of these Interfaces and the constructors and some other basics are in the PUBLIC section.
Code tools can see all of this but the compiler can not from a remote unit?
I can't say if making these PUBLIC is the correct fix or even why it was like that.
In any case the test project now compiles and executes.
I'll have to ding into this a little more, something strange indeed.
PascalDragon:
The compiler sees the TGPGraphics which indeed has DrawLine declared as private, thus it must not provide access to it (the interface isn't taken into account here).
You have to cast TGPGraphics to IGPGraphics so that you can access DrawLine. It's a bug in Lazarus that its CodeTools provide access to DrawLine when used on the TGPGraphics instance.
Navigation
[0] Message Index
[#] Next page