procedure Init_PopupList_TlsIndex;
begin
PopupList_TlsIndex := TlsAlloc;
end;
procedure Clear_PopupList_TlsIndex;
begin
TlsFree(PopupList_TlsIndex);
end;
function PopupList: TPopupList;
begin
Result := TlsGetValue(PopupList_TlsIndex);
if not Assigned(Result) then
begin
Result := TPopupList.Create;
TlsSetValue(PopupList_TlsIndex,Result);
end;
end;
procedure TPopupList.Add(Popup: TPopupMenu);
begin
if Count = 0 then FWindow := Classes.AllocateHWnd(MainWndProc);
inherited Add(Popup);
end;
procedure TPopupList.Remove(Popup: TPopupMenu);
begin
inherited Remove(Popup);
if Count = 0 then
begin
Classes.DeallocateHWnd(FWindow);
TlsSetValue(PopupList_TlsIndex,nil);
Destroy;
end;
end;