[Lazarus] TStringList as published property of a component

Alberto Manganaro alberto.manganaro at unimib.it
Thu Nov 18 12:17:34 CET 2010


Dear Michael,

thanks for your reply. But actually I already did what you suggested! 
Luckily your message made me think again and I found out that the 
problem was not there: information int the string list was correclty 
stored even when inserting strings at design-time. But these strings 
were needed to add some voices in a popup menu, and this was the point 
where things went wrong (and as I didn't see the changes in the popup, I 
was thinking that the string list was empty).

Now I put a init flag in the component, so first time that the popup 
menu is needed, it is updated with the info in the string list, and 
everything is ok!

Thanks again

A.

Il 18/11/2010 11:38, michael.vancanneyt at wisa.be ha scritto:
>
>
> On Thu, 18 Nov 2010, Alberto Manganaro wrote:
>
>> Hi,
>>
>> first of all, as it's the first time I write here, I'd like to thank
>> all the people involved in the development/testing/mantaining/etc of
>> Lazarus :-)
>>
>> I would like to understand better how to deal with the properties of a
>> visual component. My problem is the following: I'm writing a component
>> that has a property of class TStringList. This property is published,
>> so I can correctly access at design-time when I put my new component
>> in a form. But if I assign some values to the TStringList at
>> design-time, it seems that at run time that string list is empty.
>
> Never use TStringList as a property type, always use TStrings.
> (but initialize your field with a TStringList instance)
>
>> Now, if I initialize that list through code (it means that I do this
>> run time, after the component is created) everything is fine. My doubt
>> is that in the constructor of the component the string list is created
>> and initialized, so maybe this is the problem. But if I don't create
>> the string list in the constructor of the component, of course I have
>> an error.
>>
>> Can someone please explain me how properties of a component are
>> managed at design-time? How can I set my string list at design-time
>> and correctly have the values available at run-time?
>>
>
> The write must always happen through a setter procedure, and in the setter
> you must assign the strings:
>
> Property MyProp : TStrings Read FMyProp Write SetMyProp;
>
> Where SetMyProp is implemented as
>
> Procedure TmYCOmponent.SetMyProp(AValue : TStrings);
>
> begin
> if FMyProp=AValue then exit;
> FMyProp.Assign(AValue);
> end;
>
> Michael.
>
>> Thanks!

-- 
Alberto Manganaro

Milano Chemometrics and QSAR Research Group
Department of Environmental Sciences
University of Milano-Bicocca P.zza della Scienza, 1
20126 Milano - Italy

http://michem.disat.unimib.it/chm/




More information about the Lazarus mailing list