#1 2020-07-09 15:45:07

camu72
Member
From: Salta - Argentina
Registered: 2015-07-12
Posts: 28

TSynDictionary: how release objects instances in the Values TDynArray?

Hi guys, I try to do something like that:
Create a TSynDictionary with images like values, do something with that, an then release de TSynDictionary instance, but before, release the images ( or objects instances in other cases ).
This is the pseudocode:

Type
  TBitmapDynArray = array of TBitmap;
  ....
procedure myProcedure
var
  ImagesDict: TSynDictionary;
begin  
  ImagesDict := TSynDictionary.Create(TypeInfo(TIntegerDynArray),TypeInfo(TBitmapDynArray));
  
  { Loads images from a zip in a rc file }
  LoadImagen(34, 'ImgBuscar12.bmp');
  LoadImagen(15, 'ImgAgregar12.bmp');
  ...
  LoadImagen(12, 'ImgEditar12.bmp');
  
  ....
  Do_a_lot_of_thing_WithImagesIn_ImagesDict;
  ....  
  
  { magesDict.forEach(MyImagesInValues) do
    EachImage.Free } << How do somethin like that?
  // I mean, release the TObjects instances (Bitmaps in this case ) in the 
  // Values TDynArray of a TSynDictionary before free it?
  
  ImagesDict.Free; 
end;

I don't understand de use of ForEach in TSynDictionary... Can samone explainme or pointme samples?
Thanks in advance!

Offline

#2 2020-07-09 16:29:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,606
Website

Re: TSynDictionary: how release objects instances in the Values TDynArray?

If the dynamic array was registered as a T*ObjArray, then all instances will be freed.

So define and register a TBitmapObjArray = array of TBitmap.

Offline

#3 2020-07-10 00:40:13

camu72
Member
From: Salta - Argentina
Registered: 2015-07-12
Posts: 28

Re: TSynDictionary: how release objects instances in the Values TDynArray?

Thanks ab, that works...

Offline

#4 2020-07-16 22:19:31

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: TSynDictionary: how release objects instances in the Values TDynArray?

@ab

Register TBitmapObjArray where?

Offline

#5 2020-07-17 07:32:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,606
Website

Re: TSynDictionary: how release objects instances in the Values TDynArray?

Usually, in the "initialization" section of the unit defining the record type.

Offline

#6 2020-07-20 21:00:50

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: TSynDictionary: how release objects instances in the Values TDynArray?

You mean  TJSONSerializer.RegisterObjArrayForJSON()?

Offline

#7 2020-07-20 21:02:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,606
Website

Re: TSynDictionary: how release objects instances in the Values TDynArray?

Yes

Offline

Board footer

Powered by FluxBB