Recent

Author Topic: TValueListEditor.itemProps is assigning when using the := instead of replacing.  (Read 2318 times)

jamie

  • Hero Member
  • *****
  • Posts: 6077
if you do this..

 Create a TItemProp and populate it with all its inners etc.. and then do this..

 ValueListEditor.ItemProps
  • := ANewlyCreatedItemProp;


 it uses  this..
Code: Pascal  [Select][+][-]
  1. procedure TValueListEditor.SetItemProp(const AKeyOrIndex: Variant; AValue: TItemProp);
  2. begin
  3.   FStrings.GetItemProp(AKeyOrIndex).Assign(AValue);
  4. end;                

As you can see, it is assigning.. not replacing.

There is an Assign that can do this and thus not take claim.

 When I create a TitemProp.Create(ValueListEditorInstant) and  use the := , it does work
because it simiply assigns the values.

 But using HeapTrc, it leads to massive memory leaks. because the ItemProp I made never gets freed

apparently there is a ready made ItemProp for each entry in the list which is fine but it would be nice
however, if you are assigning the owner to it that it should be getting released!

The only true wisdom is knowing you know nothing

taazz

  • Hero Member
  • *****
  • Posts: 5368
if you do this..

 Create a TItemProp and populate it with all its inners etc.. and then do this..

 ValueListEditor.ItemProps
  • := ANewlyCreatedItemProp;

 it uses  this..
Code: Pascal  [Select][+][-]
  1. procedure TValueListEditor.SetItemProp(const AKeyOrIndex: Variant; AValue: TItemProp);
  2. begin
  3.   FStrings.GetItemProp(AKeyOrIndex).Assign(AValue);
  4. end;                

As you can see, it is assigning.. not replacing.

That's by design, external data will be copied in internally managed structures.

There is an Assign that can do this and thus not take claim.
Lost me there, there is only one assign usage.
When I create a TitemProp.Create(ValueListEditorInstant) and  use the := , it does work
because it simiply assigns the values.
after that you need to destroy it too, it is an externaly managed structure the component will not touch it.
But using HeapTrc, it leads to massive memory leaks. because the ItemProp I made never gets freed

apparently there is a ready made ItemProp for each entry in the list which is fine but it would be nice
however, if you are assigning the owner to it that it should be getting released!
1) Itemprop does not have an owner, ItemProplist is based on a TObjectList which by default will destroy all its objects when it gets freed. My advice, stop create Titemprop and access them directly eg
Code: Pascal  [Select][+][-]
  1. ANewlyCreatedItemProp := ValueListEditor.ItemProps[vRow];
  2.  
after that change its values and move to the row without destroying it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6077
You say it has no owner ?

 then why was I able to assign an owner ? also, it required one..
TItemProp.Create

Declaration

Source position: valedit.pas line 40

public constructor TItemProp.Create(
  AOwner: TValueListEditor
);

This is from the help file supplied.

 if what you say is true, then there is a bug because it requires an owner to create a TitemProp.

The only true wisdom is knowing you know nothing

taazz

  • Hero Member
  • *****
  • Posts: 5368
its badly named, its not an owner in the component sense. It is the container, it is used by its code to access the grid and its editors as needed at runtime. The owner mechanism is introduced in the TComponent.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018