About Terminal Server, Citrix, Delphi and other stuff
For my Terminal Server unit in the Jedi Security library I use 2 TObjectList descendants to hold a list of Terminal Server Sessions and Processes. Consider the sample below which connects to a server and enumerates all sessions:
ATerminalServer.Server := ‘TS001′;
try
if ATerminalServer.EnumerateSessions then
begin
// Now loop through the list
for i := 0 to ATerminalServer.Sessions.Count – 1 do
begin
Memo1.Lines.Add(ATerminalServer.Sessions[i].Username);
end;
end;
except
on E: EJwsclWinCallFailedException do
begin
// Handle Exception here
end;
end;
// Free Memory
ATerminalServer.Free;
end;
In the sample I loop through the sessions with a for loop. Even though Delphi supports the for in loop since Delphi 2005 it’s not possible to use this in TObjectList descendants, so we cannot use this:
To make this possible we need to implement GetEnumerator and an Enumerator class:
constructor TJwSessionsEnumerator.Create(ASessionList: TJwWTSSessionList);
begin
inherited Create;
FIndex := -1;
FSessions := ASessionList;
end;
function TJwSessionsEnumerator.GetCurrent;
begin
Result := FSessions[FIndex];
end;
function TJwSessionsEnumerator.MoveNext: Boolean;
begin
Result := FIndex < FSessions.Count – 1;
if Result then
Inc(FIndex);
end;
Now we add a function with the name GetEnumerator in the SessionList class:
And that’s really all!
Related posts:
Active Directory Altiris bug Citrix Dell Delphi Exchange Exchange2003 Exchange2010 Hewlett-Packard HP iOS Jailbreak Java LinkedIn Linux MSI MySQL Navigation Objects Office Outlook Passat PowerPoint PowerShell referall was returned RNS315 RNS510 SasLibEx script slow Terminal Server ThinApp TSAdmin TSAdminEx VBS VCDS Vista VMWare Volkswagen Windows PE WLAN Wordpress WTSWaitSystemEvent wts_event_flush
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.
One Response for "Supporting for in loop in TObjectList descendants"
[...] Go and learn more about it here. [...]
Leave a reply