* Patch from Pascal Riekenberg to make component loading thread safe (bug ID 35638)

git-svn-id: trunk@42248 -
This commit is contained in:
michael 2019-06-19 06:25:02 +00:00
parent db2c9183f1
commit ade808cb43
2 changed files with 25 additions and 5 deletions

View File

@ -1442,6 +1442,7 @@ type
FParent: TComponent;
FFixups: TObject;
FLoaded: TFpList;
FLock: TRTLCriticalSection;
FOnFindMethod: TFindMethodEvent;
FOnSetMethodProperty: TSetMethodPropertyEvent;
FOnSetName: TSetNameEvent;
@ -1456,6 +1457,8 @@ type
FOnReadStringProperty:TReadWriteStringPropertyEvent;
procedure DoFixupReferences;
function FindComponentClass(const AClassName: string): TComponentClass;
procedure Lock;
procedure Unlock;
protected
function Error(const Message: string): Boolean; virtual;
function FindMethod(ARoot: TComponent; const AMethodName: string): CodePointer; virtual;

View File

@ -609,14 +609,26 @@ begin
If (Stream=Nil) then
Raise EReadError.Create(SEmptyStreamIllegalReader);
FDriver := CreateDriver(Stream, BufSize);
InitCriticalSection(FLock);
end;
destructor TReader.Destroy;
begin
DoneCriticalSection(FLock);
FDriver.Free;
inherited Destroy;
end;
procedure TReader.Lock;
begin
EnterCriticalSection(FLock);
end;
procedure TReader.Unlock;
begin
LeaveCriticalSection(FLock);
end;
procedure TReader.FlushBuffer;
begin
Driver.FlushBuffer;
@ -1476,12 +1488,17 @@ begin
{ Don't use Result.Name directly, as this would influence
FindGlobalComponent in successive loop runs }
ResultName := CompName;
while Assigned(FindGlobalComponent(ResultName)) do
begin
Inc(i);
ResultName := CompName + '_' + IntToStr(i);
Lock;
try
while Assigned(FindGlobalComponent(ResultName)) do
begin
Inc(i);
ResultName := CompName + '_' + IntToStr(i);
end;
Result.Name := ResultName;
finally
Unlock;
end;
Result.Name := ResultName;
end;
end;