mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-25 23:49:21 +02:00
Changed the loading behavior of TComponent derived classes.
This commit is contained in:
parent
974aa20e7d
commit
701cc16d12
@ -9931,61 +9931,64 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function InitInheritedComponent(Instance: TComponent; RootAncestor: TClass): Boolean;
|
function FindInitComponentHandler(const ComponentClass: TComponentClass; var Handler: TInitHandler): Boolean;
|
||||||
Var
|
var
|
||||||
I : Integer;
|
A: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
I:=0;
|
Result := False;
|
||||||
if not Assigned(InitHandlerList) then begin
|
|
||||||
Result := True;
|
if not Assigned(InitHandlerList) then
|
||||||
Exit;
|
InitHandlerList := TList.Create;
|
||||||
|
|
||||||
|
for A := 0 to Pred(InitHandlerList.Count) do
|
||||||
|
begin
|
||||||
|
Handler := TInitHandler(InitHandlerList.Items[A]);
|
||||||
|
|
||||||
|
if Handler.AClass = ComponentClass then
|
||||||
|
Exit(True);
|
||||||
end;
|
end;
|
||||||
Result:=False;
|
|
||||||
With InitHandlerList do
|
|
||||||
begin
|
|
||||||
I:=0;
|
|
||||||
// Instance is the normally the lowest one, so that one should be used when searching.
|
|
||||||
While Not result and (I<Count) do
|
|
||||||
begin
|
|
||||||
If (Instance.InheritsFrom(TInitHandler(Items[i]).AClass)) then
|
|
||||||
Result:=TInitHandler(Items[i]).AHandler(Instance,RootAncestor);
|
|
||||||
Inc(I);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function AddInitComponentHandler(const ComponentClass: TComponentClass; const Handler: TInitComponentHandler; const ForceInsert: Boolean): TInitHandler;
|
||||||
|
|
||||||
procedure RegisterInitComponentHandler(ComponentClass: TComponentClass; Handler: TInitComponentHandler);
|
|
||||||
|
|
||||||
Var
|
|
||||||
I : Integer;
|
|
||||||
H: TInitHandler;
|
|
||||||
begin
|
begin
|
||||||
If (InitHandlerList=Nil) then
|
if ForceInsert or not FindInitComponentHandler(ComponentClass, Result) then
|
||||||
InitHandlerList:=TList.Create;
|
begin
|
||||||
H:=TInitHandler.Create;
|
Result := TInitHandler.Create;
|
||||||
H.Aclass:=ComponentClass;
|
Result.AClass := ComponentClass;
|
||||||
H.AHandler:=Handler;
|
|
||||||
try
|
InitHandlerList.Add(Result);
|
||||||
With InitHandlerList do
|
|
||||||
begin
|
|
||||||
I:=0;
|
|
||||||
While (I<Count) and not H.AClass.InheritsFrom(TInitHandler(Items[I]).AClass) do
|
|
||||||
Inc(I);
|
|
||||||
{ override? }
|
|
||||||
if (I<Count) and (TInitHandler(Items[I]).AClass=H.AClass) then
|
|
||||||
begin
|
|
||||||
TInitHandler(Items[I]).AHandler:=Handler;
|
|
||||||
H.Free;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
InitHandlerList.Insert(I,H);
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
H.Free;
|
|
||||||
raise;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Result.AHandler := Handler;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function InitInheritedComponent(Instance: TComponent; RootAncestor: TClass): Boolean;
|
||||||
|
Var
|
||||||
|
I: Integer;
|
||||||
|
|
||||||
|
Handler: TInitHandler;
|
||||||
|
|
||||||
|
ComponentClass: TComponentClass;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Handler := nil;
|
||||||
|
Result := not Assigned(InitHandlerList);
|
||||||
|
|
||||||
|
if not Result then
|
||||||
|
begin
|
||||||
|
ComponentClass := TComponentClass(Instance.ClassType);
|
||||||
|
|
||||||
|
if not FindInitComponentHandler(ComponentClass, Handler) then
|
||||||
|
Handler := AddInitComponentHandler(ComponentClass, @DefaultInitHandler, True);
|
||||||
|
|
||||||
|
Result := Handler.AHandler(Instance,RootAncestor);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure RegisterInitComponentHandler(ComponentClass: TComponentClass; Handler: TInitComponentHandler);
|
||||||
|
begin
|
||||||
|
AddInitComponentHandler(ComponentClass, Handler, False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user