I'm streaming out some forms and reading them back in at a later date.  My
problem is that before reading them in, RegisterClass needs to be called for
all of the classes of the components I'm reading (assuming these classes
aren't already registered).  So,

1/.  Is there any reason why I can't just write out some class definitions
before writing my forms, and before reading them in again, read and register
the classes, eg.
// Write out
var MyClass: TPersistentClass;
  MyClass := TButton;
  MyStream.Write(MyClass, SizeOf(TPersistentClass));
// Read in
  MyStream.Read(MyClass, SizeOf(TPersistentClass));
  RegisterClass(MyClass);
?

2/.  Is there an easier way than the following to get the class of an object
(and is this method ok)?
  type
    TClassDef = class(TPersistent)
      class function GetClass: TPersistentClass;
    end;
  function TClassDef.GetClass: TPersistentClass;
  begin
    Result := Self;
  end;
(eg, MyClass := TClassDef(Button1).GetClass;)

I don't know much about the internal structure of a TClass/TPersistentClass,
so I don't know if these sorts of things are "safe".  I imagine that I'm
making the assumption that the class definitions aren't different in the
program that's reading them in, but I don't know whether that's a dangerous
assumption to make.  Is there a better way to do this?

(Incidently, has mail been bouncing from my address?  Apologies if so, on
behalf of the installers of the new firewall here, which it seems was a
little too efficient - I've had no mail all morning anyway)

Cheers,
Carl

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to