TStream.ReadComponent returns Error stating it can't find the Class? lazarus / 31-LCL ---------------------------------------------------------------------- jamie · 2022-02-13 23:15 I have written a Tbutton component to a stream using the MyStream.WriteComponent(..... that all works Reset the stream back to 0 position and then attempt to read it back using  MyStream.WriteComponent(NIL) and it simply insist it can't find the class TBUTTON.  I have looked high and low and all documentation clearly states if the given instance is NIL then it will create a new instance based on that class info found in the stream.  Well, it does find the TBUTTON in the stream, but it claims to not be able to find the TBUTTON class to create it.  If I first create a Tbutton and then use that for the instance it works, it will redefine the instance with its new values but that isn't what I want, I want it to create the instance so I can manage it as it reads the stream until a stream error takes place at which point I know I have made it to the end.  can someone shed some light on this?  Apparently, I am not the only one with this issue, I've found it all over the net etc. ---------------------------------------------------------------------- Martin_fr · 2022-02-13 23:39 TReader has a callback. But the simplest is to do "RegisterClass(  TYourButton );" It will also find it if Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TFoo = classpublished  YourButtonName: TYourButton;end; ReadComponent(AFoo); // or ReadRootComponent ---------------------------------------------------------------------- jamie · 2022-02-14 00:00 I've played with TReader too, it has the same issues. However, I did get the ReadComponent to work but I had to use the "RegisterClass('Tbutton')" before it will create the new component from the stream.  It appears there is no registered classes active at this point?  Is this a per unit bases that requires these classes to be registered when we need to do this ?  I did all of this from the main unit with a simple form that already has a TButton on it, in fact I use that same Tbutton to generate the stream to test with, all of that works fine but resetting the stream back to the start and attempting to read it back fails because the class Tbutton isn't registered.  Is this normal practice for the LCL to blow this stuff away once up and running ? ---------------------------------------------------------------------- Martin_fr · 2022-02-14 00:25 Quote from: jamie on February 14, 2022, 01:00:20 am I did all of this from the main unit with a simple form that already has a TButton on it, in fact I use that same Tbutton to generate the stream to test with, all of that works fine but resetting the stream back to the start and attempting to read it back fails because the class Tbutton isn't registered.  Is this normal practice for the LCL to blow this stuff away once up and running ? Not sure. But if you have a root component, that you instantiate yourself, and that root component has published fields with the required class, and you pass this instance in as root => then it should find the classes from the RTTI. (hence they must be published).