Carl
Put the RegisterClass call in the 'initialization' section at the end of
your unit where the class is declared
Also be careful on TCollectionItem derived classes (such as TMenuItem) as
they are
not named and you cant stream in over an exising one
On this subject have you come across any method/code to derive a
differential DFM
(ie you change a layout and you want to only store the DFM of the altered
properties)
Regards
Neven
----- Original Message -----
From: Carl Reynolds <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Tuesday, 23 May 2000 14:24
Subject: [DUG]: Registering classes
> 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
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz