Recent

Author Topic: What happens if you use "RegisterClass" that is already registered?  (Read 291 times)

jamie

  • Hero Member
  • *****
  • Posts: 7402
Although I have not fully tested this but, the question remains!

 What happens if I register a class of my own that just happens to be already registered but not the same?
 
 This is for use with the streaming system, and I can picture a class being changed from some other part of the app?

Jamie
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 18521
  • Here stood a man who saw the Elbe and jumped it.
Re: What happens if you use "RegisterClass" that is already registered?
« Reply #1 on: November 09, 2025, 01:39:12 pm »
Well, simply try?
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. uses classes;
  3. type
  4. {$M+}
  5.   TMyClass = class(TPersistent)
  6.   private
  7.     FDummy:integer;
  8.   published
  9.     property dummy:integer read FDummy write Fdummy;
  10.   end;
  11.  
  12. begin
  13.   RegisterClass(TMyClass);
  14.   RegisterClass(TMyClass);// ergo: nothing happens
  15. end.
Delphi says this:
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.RegisterClass

Registering the same class twice:nothing happens
Registering two classes with the same name:exception is raised.

Test that yourself.
« Last Edit: November 09, 2025, 01:46:49 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018