Forum > General

specialize TObjectList

(1/2) > >>

Dzandaa:
 Hi everybody,

 Working with Lazarus Pascal 2.012 FPC 2.3.0 on Windows and Linux
I'm new to Lazarus for a few months so be cool :)

 I have 3 Units to create a Card Game:
 
 A Form Unit for the main program
 A Card Unit to store the Card Parameters (Class TCard).
 A Deskcreator Unit to create a desk card (Class TDeskCreator).
 Containing :


--- 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";}};} --- public  CardsList: specialize TObjectList<Tcard>; // To store the list of Cards   function CreateCards():specialize TObjectList<Tcard>; to create the Desk Card  function TDeskCreator.CreateCards():specialize TObjectList<Tcard>; var  ... begin  CardsList := specialize TObjectList<Tcard>.Create;  ...   CardsList.Add(NewCard);    ...  // Here CardList.Count = 52, it's O.K.  // All Cards in the List are valid  exit(CardsList);// also try Result := CardsList; end 
A Form Unit for the main program (Class TCardMagicForm).
 Containing:


--- 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";}};} ---private MyDesk: TDeskCreator;   Cards: specialize TObjectList<Tcard>;     procedure TCardMagicForm.InitDesk();begin  MyDesk := TDeskCreator.Create;   Cards := MyDesk.CreateCards(); // Here Cards.Count = 0, Not O.K.end;    
My problem:

I don't know how to return my TObjectList from my Deskcreator to my main program...

The Count in the list is always 0 in the main form.

If I remove the Deskcreator Unit and put all except the TCard Unit in the main Form, it is working !!!

Any idea?


howardpc:
TObjectList is not a generic container.
You probably want something like TFPGObjectList from the unit fgl.

bytebites:

--- Quote from: howardpc on November 28, 2021, 02:52:34 pm ---TObjectList is not a generic container.
You probably want something like TFPGObjectList from the unit fgl.

--- End quote ---

But TObjectList from Generics.Collections is generic.

PascalDragon:

--- Quote from: Dzandaa on November 28, 2021, 01:19:10 pm ---If I remove the Deskcreator Unit and put all except the TCard Unit in the main Form, it is working !!!

--- End quote ---

Would you please provide a small, but complete example, so that we can try your code ourselves? Working with code snippets more often than not does not contain the part that is really relevant.

jamie:
I don't know if it makes any difference but what I noticed is the collections units is all in Delphi Mode using "Abtract" and code here is using fpc mode specialized etc..

  I don't know if that makes any difference between units and using different modes

Navigation

[0] Message Index

[#] Next page

Go to full version