Recent

Author Topic: Effect of streaming in a component with some settings or subcomponents missing?  (Read 342 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
When you update a live component from a stream, and in the stream some of the fields or sub-components present in the component are missing, will the fields and subcomponents be left as they are, or will they be overwritten?

Eg say I have a panel with an edit box in it, and I write in a component stream of the panel that has a different colour, but doesn't have the edit box.

Will the edit box stay in place or will it be deleted?

I suspect existing fields are left alone if they are not included in the data being streamed in.

If existing values not present in the stream are not deleted, is that by accident or design, or is it an inherent feature of the streaming process?
Lazarus 3.0/FPC 3.2.2

Thaddy

  • Hero Member
  • *****
  • Posts: 15923
  • Censorship about opinions does not belong here.
The instream has to match exactly with the outstream. Otherwise it would probably crash or has undefined behavior.
If I smell bad code it usually is bad code and that includes my own code.

BildatBoffin

  • New Member
  • *
  • Posts: 29
Yes they are left as-is. The remedy is to use the stored modifier and set it to true so that when you write your stream everything gets included. Then when reading the stream the problem is gone.

See https://www.freepascal.org/docs-html/ref/refsu38.html.

Obviously for this to work you have to have the full control on the properties of your component.

Thaddy

  • Hero Member
  • *****
  • Posts: 15923
  • Censorship about opinions does not belong here.
Obviously for this to work you have to have the full control on the properties of your component.
Usually, yes, but see remark 5 in the docs you point to: you can derive a class where the modifiers are overridden and you can subsequently use that class just to hardcast the real class on store and read back. Remember that the layout of a class of component should not be changed.
in the case of components, you can also derive your own component+ editor, but the hardcast will work without writing a full component.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018