type
TSession = class
private
function GetName: String; // basically Exit (FName)
procedure SetName (AName: String) // basically FName := AName
FName: String;
public
property Name: String read GetName write SetName;
end;
type
TMain = class
private
function GetSession (AID: Integer): TSession;
function GetSessionName (AID: Integer): String;
procedure SetSessionName (AID: Integer; AName: String);
FLock: TCriticalSection;
FSessions: specialize TDictionary<Integer,TSession>;
public
public SessionName[ID: Integer]: String read GetSessionName write SetSessionName;
end;
function TMain.GetSession (AID: Integer): TSession;
begin
FLock.Enter;
try
Exit (FLock.Items[AID]);
finally
FLock.Leave;
end;
end;
function TMain.GetSessionName (AID: Integer): String;
var s: TSession;
begin
s := GetSession(AID);
if Assigned(s) then Exit (s.Name) else exit ('');
end;
procedure TMain.SetSessionName (AID: Integer; AName: String);
var s: TSession;
begin
s := GetSession(AID);
if Assigned(s) then s.Name := AName;
end;