Forum > Beginners

[SOLVED]Diferences in Generics in mode FPC or Delphi

(1/2) > >>

janasoft:
Hello.
Next code compile and work correctly


--- 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";}};} ---{$APPTYPE CONSOLE}{$mode Delphi} program project1; uses generics.collections; type  TEntity= class  ID: integer;  end;   TInheritedEntity = class(TEntity)  Name: string  end;   TEntityList = TObjectList <TEntity>;  TInheritedEntityList = TObjectList <TInheritedEntity>;    TSubject = class    EntityList: TEntityList;  end;    TInheritedSubject = class (TSubject)    EntityList: TInheritedEntityList;  end;   var subject: TSubject;      inheritedSubject: TInheritedSubject;      ent: TEntity;      inheritedEnt: TInheritedEntity; begin  ent:= TEntity.Create;  ent.ID:=0;  inheritedEnt:= TInheritedEntity.Create;  inheritedEnt.ID:=1;  inheritedEnt.Name:='Entity';   subject:= TSubject.create;  subject.EntityList:=TEntityList.Create;   inheritedSubject:= TInheritedSubject.create;  inheritedSubject.EntityList:=TInheritedEntityList.Create;   subject.EntityList.Add(ent);  inheritedSubject.EntityList.Add(inheritedEnt);   writeln(subject.EntityList.Items[0].ClassName);  writeln(subject.EntityList.Items[0].ID);  writeln(inheritedSubject.EntityList.Items[0].ClassName);  writeln(inheritedSubject.EntityList.Items[0].ID);  writeln(inheritedSubject.EntityList.items[0].Name);  writeln; write('type enter'); Readln;   subject.EntityList.free;  subject.Free;  inheritedSubject.EntityList.Free;  inheritedSubject.Free;end.                  
But if i try the same code with FP Generics


--- 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";}};} ---{$APPTYPE CONSOLE}{$mode ObjFPC} program project1;  uses  fgl;   type   TEntity= class   ID: integer;   end;    TInheritedEntity = class(TEntity)   Name: string   end;    TEntityList = specialize TFPGObjectList <TEntity>;   TInheritedEntityList = specialize TFPGObjectList <TInheritedEntity>;    TSubject = class     EntityList: TEntityList;   end;    TInheritedSubject = class (TSubject)     EntityList: TInheritedEntityList;   end;    var subject: TSubject;       inheritedSubject: TInheritedSubject;       ent: TEntity;       inheritedEnt: TInheritedEntity;      
I get the error: Duplicate identifier "EntityList"

I supose that I am doing something wrong or is this the way it has to work?

Regards

Lazarus 2.2.6 (rev lazarus_2_2_6) FPC 3.2.2 x86_64-win64-win32/win64

jamie:
maybe put this at the top ?

{$modeSwitch DUPLICATELOCALS}

janasoft:
Many thanks for your answer jamie but I get the same error

bytebites:
Change to delphi-mode

cdbc:
Hi
You've defined:
--- 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    EntityList: TEntityList;  end;    TInheritedSubject = class (TSubject)    EntityList: TInheritedEntityList;  end; without visibility specifier and by convention they're then "public" / "published" depending on {$M+/-}
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

Navigation

[0] Message Index

[#] Next page

Go to full version