[Lazarus] Can I delete a property from a collectionitem

Marc Weustink marc at dommelstein.nl
Thu Oct 13 11:00:46 CEST 2022



On 12-10-2022 18:21, Michael Van Canneyt via lazarus wrote:
> 
> 
> On Wed, 12 Oct 2022, nibbikfrans via lazarus wrote:
> 
>> Hi,
>>
>> I have a collection stored in a file. One property of each 
>> collectionitem is a value of what seeems to be a set but is not. That 
>> property is no longer needed. Is there a way to delete that property? 
>> I suppose I can do that by creating a new collectionitem type without 
>> that property and migrate the data. But then a have a different 
>> collection which meens a have to make lots of changes.
> 
> Yet that is the only correct way.
> 
> If you can make a descendent, you can
> override the property and simply discard the value when it is set in the
> setter.
> 

What you also can do is remove the property and override the 
DefineProperties method of your CollectionItem object and add a dummy 
reader for your propertyname. This way you will be able to read old data 
and in new data it won't get written.

I didn't test this on FPC, but I've done it this way several times in 
Delphi.

Marc


>>
>> If deleting a property isn't possible, how can I delete the value of 
>> that property?
> 
> In the file, in the instance of the collectionitem or where ?
> 
>>
>> And an extra question is: how can I test whether the property has a 
>> value or not?
>>
>> The possible value is defined as followes:
>> TTest = (test1, test2, test3);
>> TTestValues = set ot TTest;
> 
> The property has a set as value ?
> 
> If the set is empty, then the property has no value ? Unless empty value 
> is also a value.
> 
> Michael.


More information about the lazarus mailing list