Well the package itself knows what it contains. So the package itself can have a method that does not need to search, but rather has a hardcoded reference for each included class.
That method it the package, which knows it all, is called: Register.
Check out a package, in the package options you can specify if and which unit has the register method.
Each package also has an automatically created unit. That contains a "uses" for all classes.
And in that unit you will find
procedure Register;
begin
RegisterUnit('SynEdit', @SynEdit.Register);
end;
initialization
RegisterPackage('SynEdit', @Register);
So the IDE knows:
- there is a package SynEdit
- One of its units is called SynEdit too.
And that unit has a register method.
The IDE will call this method, and this method then calls RegisterClass or RegisterComponent.
The register procedure in the unit SynEdit is hand written. And it know (hardcoded) which classes to register.
Note: The IDE also has the configuration which classes are actually added to he IDE.
So if SynEdit was not added, but used by another package (the other package being added), then the IDE knows.
SynEdit would still do RegisterPackage. But the IDE would not look for the name "SynEdit" so the entry would be ignored.
The IDE would in that case not call the registered "Register" method.