看看以下代码,找找线索
================
function TReader.ReadRootComponent(Root: TComponent): TComponent;
function FindUniqueName(const Name: string): string;
var
I: Integer;
begin
I := 0;
Result := Name;
while not IsUniqueGlobalComponentName(Result) do
begin
Inc(I);
Result := Format('%s_%d', [Name, I]);
end;
end;
var
I: Integer;
Flags: TFilerFlags;
G: TList;
begin
ReadSignature;
Result := nil;
{$IFDEF MSWINDOWS}
GlobalNameSpace.BeginWrite; // Loading from stream adds to name space
try
{$ENDIF}
try
ReadPrefix(Flags, I);
if Root = nil then
begin
Result := TComponentClass(FindClass(ReadStr)).Create(nil);
function FindClass(const ClassName: string): TPersistentClass;
begin
Result := GetClass(ClassName);
if Result = nil then ClassNotFound(ClassName);
end;
procedure ClassNotFound(const ClassName: string);
begin
raise EClassNotFound.CreateFmt(SClassNotFound, [ClassName]);
end;
SClassNotFound = 'Class %s not found'; |