Forum > Beginners

[SOLVED]Diferences in Generics in mode FPC or Delphi

<< < (2/2)

I'm usually not a defender of $mode objfpc, but in this case I think it is right, having a class with two different (and differently typed) entitylist fields is a mess.

Hello and first of all, thanks for your answers.

--- Quote from: bytebites on November 28, 2023, 09:47:42 am ---Change to delphi-mode

--- End quote ---
@bytebites In Delphi mode works correctly. The question is exactly that. Why works correctly in Delphi Mode and fails in FPC mode? What's the difference between both modes?

--- Quote from: cdbc on November 28, 2023, 09:50:41 am ---That means you WILL have a duplicate identifier. You could put EntityList in "private" then they can't see eachother, but if it's a solution for you, I dunno...
edit: in different units they can't see eachother...
Regards Benny

--- End quote ---

@cdbc I've made this change

--- 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";}};} ---   TSubject = class   strict private     FEntityList: TEntityList;     procedure SetEntityList(AValue: TEntityList);   public     property EntityList:TEntityList read FEntityList write SetEntityList;   end;Now  theres is no problem at the moment of declare the variables, but now I get the error 'Incompatible type for arg no. 1: Got "TFPGObjectList<project1.TInheritedEntity>", expected "TFPGObjectList<project1.TEntity>".
So I think it is not an issue of visibility but of type assigning.

@marcov, this is only an exercice about Generics writen in Delphi that I wanted to translate to Lazarus to try to aplicate this technique in order to solve a problem in an aplication. I'm not an expert in lazarus, so I'm sure that there will be better solutions to my problem, but that is not the case. What I really want to know is, like I've told before, why the code in Delphi mode works correctly and fails in FPC mode?

Anyway, thanks again to all for your interest


--- Quote from: janasoft on November 28, 2023, 04:25:41 pm ---What I really want to know is, like I've told before, why the code in Delphi mode works correctly and fails in FPC mode?

--- End quote ---

Exactly because of what I said. That construct (with one identifier shadowing the other) is considered bad behaviour, and objfpc mode was meant as a cleaned up version of Delphi, so doesn't allow it.

Many thanks @marcov. My doubt is solved.


[0] Message Index

[*] Previous page

Go to full version