Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-12

streaming readonly properties

16 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vincent Snijders

Hi,

I am looking at http://www.freepascal.org/mantis/view.php?id=7638. This is a bug which only occurs with fpc 2.1.1, not with fpc 2.0.4.

With fpc 2.1.1 the EditLabel property of a TLabelEdit is not streamed. It is declared like:

     property EditLabel: TBoundLabel read FEditLabel;

I stepped through the code and found out, that it skips writing the property in TWriter.WriteProperty because of the following check: if (not Assigned(PPropInfo(PropInfo)^.SetProc)) or (not Assigned(PPropInfo(PropInfo)^.GetProc)) then

     exit;

Apparently the SetProc is not assigned.

FPC 2.0.4 has the same code in TWriter.WriteProperty. I conclude that the RTTI is different between these two versions.

Questions:
* Are readonly properties like EditLabel streamable or should they always have a write specifier?
* Is this a bug in fpc 2.0.4 or in fpc 2.1.1, IOW is the difference between fpc 2.0.4 a regression or a bug fix?

Vincent

Reply by email

Aleš Katona
to Vincent Snijders

Hi, I recently changed TReader and TWriter to be delphi compatible (they were missing a virtual "read" and a virtual "write".

It might be related, best idea is to see if all TWriter/TReader descendants which add "read" and "write" have them use override.

As for the concrete problem.. not sure if it's truly related or not bug I guess RTTI did change.

PS: I did fix TDelphiReader and TDelphiWriter to override but didn't find any other direct descendants in RTL/FCL/LCL by grep (I admit it's not the way to search for them).

Ales

Reply by email

Vincent Snijders
to Aleš Katona
Aleš Katona wrote 8 lines
Hi, I recently changed TReader and TWriter to be delphi compatible (they were missing a virtual "read" and a virtual "write". It might be related, best idea is to see if all TWriter/TReader descendants which add "read" and "write" have them use override. As for the concrete problem.. not sure if it's truly related or not bug I guess RTTI did change.

No, your changes are made after the bug report, so they are not the cause of the bug, at most the cause the problem I see now, but not likely.

PS: I did fix TDelphiReader and TDelphiWriter to override but didn't find any other direct descendants in RTL/FCL/LCL by grep (I admit it's not the way to search for them).

The TLRSObjectReader inherits from TAbstractObjectReader and has a

	procedure Read(var Buf; Count: LongInt);

Would that be affected by your patch?

Vincent

Reply by email

Unknown author

As said in an earlier mail I have problems streaming the property EditLabel: TBoundLabel read FEditLabel;
of a TLabeledEdit with fpc 2.1.1.

Some discussion on #fpc led to the conclusion that streaming a readonly persistant should be allowed, because you write to the properties of the readonly persistant property.

Attached is a proposal to fix it.

Vincent

Reply by email

Michael Van Canneyt
to Unknown author
Show quoted text 7 lines
As said in an earlier mail I have problems streaming the property EditLabel: TBoundLabel read FEditLabel; of a TLabeledEdit with fpc 2.1.1. Some discussion on #fpc led to the conclusion that streaming a readonly persistant should be allowed, because you write to the properties of the readonly persistant property. Attached is a proposal to fix it.

Delphi does not stream readonly properties. So we won't either.

The proper solution for this is support for csSubComponent in TComponent.

Michael.

Reply by email

Vincent Snijders
to Michael Van Canneyt
Michael Van Canneyt wrote 14 lines
On Tue, 12 Dec 2006, wrote: > As said in an earlier mail I have problems streaming the > property EditLabel: TBoundLabel read FEditLabel; > of a TLabeledEdit with fpc 2.1.1. > > Some discussion on #fpc led to the conclusion that streaming a readonly persistant should be allowed, because you write to the properties of the readonly persistant property. > > Attached is a proposal to fix it. Delphi does not stream readonly properties. So we won't either. The proper solution for this is support for csSubComponent in TComponent.

Can you elaborate a bit, what you mean by that? What should be changed and where?

Vincent

Reply by email

Michael Van Canneyt
to Vincent Snijders
Vincent Snijders wrote 20 lines
Michael Van Canneyt schreef: > > On Tue, 12 Dec 2006, wrote: > > > As said in an earlier mail I have problems streaming the property > > EditLabel: TBoundLabel read FEditLabel; > > of a TLabeledEdit with fpc 2.1.1. > > > > Some discussion on #fpc led to the conclusion that streaming a readonly > > persistant should be allowed, because you write to the properties of the > > readonly persistant property. > > > > Attached is a proposal to fix it. > > Delphi does not stream readonly properties. So we won't either. > > The proper solution for this is support for csSubComponent in TComponent. Can you elaborate a bit, what you mean by that? What should be changed and where?

Delphi has a ComponentState csSubComponent. This flag should be set if you publish a property of type TComponent, and the TComponent instance is 'owned' by the object that publishes it, i.e. it's NOT a reference to an other existing TComponent.

The owned TComponent has 'csSubComponent' in it's componentstyle. This tells delphi to stream the component's properties as part of it's owning component, and not just a reference to it.

The IDE will need support for this, as well TComponent and the streaming system. (The latter part is probably the easy part ;) )

Michael.

Reply by email

Vincent Snijders
to Michael Van Canneyt
Michael Van Canneyt wrote 32 lines
On Wed, 13 Dec 2006, Vincent Snijders wrote: > Michael Van Canneyt schreef: >> On Tue, 12 Dec 2006, wrote: >> >>> As said in an earlier mail I have problems streaming the property >>> EditLabel: TBoundLabel read FEditLabel; >>> of a TLabeledEdit with fpc 2.1.1. >>> >>> Some discussion on #fpc led to the conclusion that streaming a readonly >>> persistant should be allowed, because you write to the properties of the >>> readonly persistant property. >>> >>> Attached is a proposal to fix it. >> Delphi does not stream readonly properties. So we won't either. >> >> The proper solution for this is support for csSubComponent in TComponent. > Can you elaborate a bit, what you mean by that? What should be changed and > where? Delphi has a ComponentState csSubComponent. This flag should be set if you publish a property of type TComponent, and the TComponent instance is 'owned' by the object that publishes it, i.e. it's NOT a reference to an other existing TComponent. The owned TComponent has 'csSubComponent' in it's componentstyle. This tells delphi to stream the component's properties as part of it's owning component, and not just a reference to it. The IDE will need support for this, as well TComponent and the streaming system. (The latter part is probably the easy part ;) )

So far so good.

The IDE supports this (no drop downbox in the IO, but you can expand to set the owned component's properties). The owned component has the csSubComponent in its component style:

   Include(FEditLabel.ComponentStyle, csSubComponent);
   Include(FEditLabel.ControlStyle, csNoDesignSelectable);

So where should the streaming occur?

Should I amend to patch to allow streaming properties of readonly subcomponents?

Vincent

Reply by email

Michael Van Canneyt
to Vincent Snijders
Vincent Snijders wrote 47 lines
Michael Van Canneyt schreef: > > On Wed, 13 Dec 2006, Vincent Snijders wrote: > > > Michael Van Canneyt schreef: > > > On Tue, 12 Dec 2006, wrote: > > > > > > > As said in an earlier mail I have problems streaming the property > > > > EditLabel: TBoundLabel read FEditLabel; > > > > of a TLabeledEdit with fpc 2.1.1. > > > > > > > > Some discussion on #fpc led to the conclusion that streaming a > > > > readonly > > > > persistant should be allowed, because you write to the properties of > > > > the > > > > readonly persistant property. > > > > > > > > Attached is a proposal to fix it. > > > Delphi does not stream readonly properties. So we won't either. > > > > > > The proper solution for this is support for csSubComponent in > > > TComponent. > > Can you elaborate a bit, what you mean by that? What should be changed and > > where? > > Delphi has a ComponentState csSubComponent. This flag should be set > if you publish a property of type TComponent, and the TComponent instance > is 'owned' by the object that publishes it, i.e. it's NOT a reference to an > other existing TComponent. > > The owned TComponent has 'csSubComponent' in it's componentstyle. This tells > delphi to stream the component's properties as part of it's owning > component, and not just a reference to it. > > The IDE will need support for this, as well TComponent and the streaming > system. (The latter part is probably the easy part ;) ) So far so good. The IDE supports this (no drop downbox in the IO, but you can expand to set the owned component's properties). The owned component has the csSubComponent in its component style: Include(FEditLabel.ComponentStyle, csSubComponent); Include(FEditLabel.ControlStyle, csNoDesignSelectable); So where should the streaming occur?

When EditLabel is encountered ?

Should I amend to patch to allow streaming properties of readonly subcomponents?

Yes, please do. It should be quite like the check you made before...

Michael.

Reply by email

Vincent Snijders
to Michael Van Canneyt
Michael Van Canneyt wrote 49 lines
On Wed, 13 Dec 2006, Vincent Snijders wrote: > Michael Van Canneyt schreef: >> On Wed, 13 Dec 2006, Vincent Snijders wrote: >> >>> Michael Van Canneyt schreef: >>>> On Tue, 12 Dec 2006, wrote: >>>> >>>>> As said in an earlier mail I have problems streaming the property >>>>> EditLabel: TBoundLabel read FEditLabel; >>>>> of a TLabeledEdit with fpc 2.1.1. >>>>> >>>>> Some discussion on #fpc led to the conclusion that streaming a >>>>> readonly >>>>> persistant should be allowed, because you write to the properties of >>>>> the >>>>> readonly persistant property. >>>>> >>>>> Attached is a proposal to fix it. >>>> Delphi does not stream readonly properties. So we won't either. >>>> >>>> The proper solution for this is support for csSubComponent in >>>> TComponent. >>> Can you elaborate a bit, what you mean by that? What should be changed and >>> where? >> Delphi has a ComponentState csSubComponent. This flag should be set >> if you publish a property of type TComponent, and the TComponent instance >> is 'owned' by the object that publishes it, i.e. it's NOT a reference to an >> other existing TComponent. >> >> The owned TComponent has 'csSubComponent' in it's componentstyle. This tells >> delphi to stream the component's properties as part of it's owning >> component, and not just a reference to it. >> >> The IDE will need support for this, as well TComponent and the streaming >> system. (The latter part is probably the easy part ;) ) > So far so good. > > The IDE supports this (no drop downbox in the IO, but you can expand to set > the owned component's properties). The owned component has the csSubComponent > in its component style: > > Include(FEditLabel.ComponentStyle, csSubComponent); > Include(FEditLabel.ControlStyle, csNoDesignSelectable); > > So where should the streaming occur? When EditLabel is encountered ?

I am not sure I understand your question.

EditLabel is a published property of TLabeledEdit.

Show quoted text 5 lines
> Should I amend to patch to allow streaming properties of readonly > subcomponents? Yes, please do. It should be quite like the check you made before...

I will try.

Vincent

Reply by email

Michael Van Canneyt
to Vincent Snijders
Vincent Snijders wrote 61 lines
Michael Van Canneyt schreef: > > On Wed, 13 Dec 2006, Vincent Snijders wrote: > > > Michael Van Canneyt schreef: > > > On Wed, 13 Dec 2006, Vincent Snijders wrote: > > > > > > > Michael Van Canneyt schreef: > > > > > On Tue, 12 Dec 2006, wrote: > > > > > > > > > > > As said in an earlier mail I have problems streaming the property > > > > > > EditLabel: TBoundLabel read FEditLabel; > > > > > > of a TLabeledEdit with fpc 2.1.1. > > > > > > > > > > > > Some discussion on #fpc led to the conclusion that streaming a > > > > > > readonly > > > > > > persistant should be allowed, because you write to the properties > > > > > > of > > > > > > the > > > > > > readonly persistant property. > > > > > > > > > > > > Attached is a proposal to fix it. > > > > > Delphi does not stream readonly properties. So we won't either. > > > > > > > > > > The proper solution for this is support for csSubComponent in > > > > > TComponent. > > > > Can you elaborate a bit, what you mean by that? What should be changed > > > > and > > > > where? > > > Delphi has a ComponentState csSubComponent. This flag should be set > > > if you publish a property of type TComponent, and the TComponent > > > instance > > > is 'owned' by the object that publishes it, i.e. it's NOT a reference to > > > an > > > other existing TComponent. > > > > > > The owned TComponent has 'csSubComponent' in it's componentstyle. This > > > tells > > > delphi to stream the component's properties as part of it's owning > > > component, and not just a reference to it. > > > > > > The IDE will need support for this, as well TComponent and the streaming > > > system. (The latter part is probably the easy part ;) ) > > So far so good. > > > > The IDE supports this (no drop downbox in the IO, but you can expand to > > set > > the owned component's properties). The owned component has the > > csSubComponent > > in its component style: > > > > Include(FEditLabel.ComponentStyle, csSubComponent); > > Include(FEditLabel.ControlStyle, csNoDesignSelectable); > > > > So where should the streaming occur? > > When EditLabel is encountered ? I am not sure I understand your question. EditLabel is a published property of TLabeledEdit.

I know that, but it was not a question, so read as

"When EditLabel is encountered."

:-)

When you do the streaming, I assume you'll have to set some extra flag in the stream, probably you'll need to check Delphi streaming code for the value of this flag... (but I'm not sure)

Michael.

Reply by email

Martin Schreiber
to Unknown author: As said in an earlier mail I have problems streaming the property EditLabel: TBoundLabel…
As said in an earlier mail I have problems streaming the property EditLabel: TBoundLabel read FEditLabel; of a TLabeledEdit with fpc 2.1.1.

A usual solution:

 ttestcomp = class(tcomponent)
  private
   fsubcomponent: ttestsubcomponent;
   procedure setsubcomponent(const avalue: ttestsubcomponent);
  //...
  published
   property subcomponent: ttestsubcomponent read fsubcomponent
                           write setsubcomponent;
 end;
implementation
procedure ttestcomp.setsubcomponent(const avalue: ttestsubcomponent);
begin
 fsubcomponent.assign(avalue);
end;

Martin

Reply by email

Vincent Snijders
to Martin Schreiber
Martin Schreiber wrote 25 lines
On Tuesday 12 December 2006 14.54, wrote: > As said in an earlier mail I have problems streaming the > property EditLabel: TBoundLabel read FEditLabel; > of a TLabeledEdit with fpc 2.1.1. > A usual solution: ttestcomp = class(tcomponent) private fsubcomponent: ttestsubcomponent; procedure setsubcomponent(const avalue: ttestsubcomponent); //... published property subcomponent: ttestsubcomponent read fsubcomponent write setsubcomponent; end; implementation procedure ttestcomp.setsubcomponent(const avalue: ttestsubcomponent); begin fsubcomponent.assign(avalue); end;

The problem with this solution, is the "write setsubcomponent;" part of the declaration.

I don't want the users of the LabeledEdit component can change the Label subcomponent.

Vincent

Reply by email

Martin Schreiber
to Vincent Snijders
Vincent Snijders wrote 12 lines
> > procedure ttestcomp.setsubcomponent(const avalue: ttestsubcomponent); > begin > fsubcomponent.assign(avalue); > end; The problem with this solution, is the "write setsubcomponent;" part of the declaration. I don't want the users of the LabeledEdit component can change the Label subcomponent.

" fsubcomponent.assign(avalue);"
does not change the instance of the subcomponent, it copies some properties from avalue to fsubcomponent if fsubcomponent.assign or avalue.assignto are implemented, otherwise it throws an exception.

Martin

Reply by email

Vincent Snijders
to Martin Schreiber
Martin Schreiber wrote 17 lines
On Thursday 14 December 2006 08.54, Vincent Snijders wrote: >> procedure ttestcomp.setsubcomponent(const avalue: ttestsubcomponent); >> begin >> fsubcomponent.assign(avalue); >> end; > The problem with this solution, is the "write setsubcomponent;" part of the > declaration. > > I don't want the users of the LabeledEdit component can change the Label > subcomponent. > " fsubcomponent.assign(avalue);" does not change the instance of the subcomponent, it copies some properties from avalue to fsubcomponent if fsubcomponent.assign or avalue.assignto are implemented, otherwise it throws an exception.

I understand now. Thanks for explaining this.

Vincent

Reply by email