Overview
The training uses Indy (IdTCPClient) solely to check internet connectivity by opening a TCP connection to www.embarcadero.com:80. Indy is a legacy networking library; Delphi has included the modern System.Net.HttpClient stack since XE8. The Indy dependency should be removed and replaced with a native connectivity check.
Background
Current Pattern
uses IdComponent, IdTCPClient;
function IsConnected: Boolean;
var
TCP: TIdTCPClient;
begin
TCP := TIdTCPClient.Create(nil);
try
TCP.Host := 'www.embarcadero.com';
TCP.Port := 80;
TCP.Connect;
Result := TCP.Connected;
except
Result := False;
finally
TCP.Free;
end;
end;
This is wrapped in a TTask.Future<Boolean> for async execution.
Problems
- Indy is installed with Delphi but is increasingly unmaintained and flagged by static analysis tools.
- TCP port 80 connections are often blocked by corporate firewalls; HTTP/HTTPS is more reliable.
System.Net.HttpClient (already used elsewhere in the project for the Maps API) achieves the same goal with a HEAD request and no extra dependency.
Replacement Strategy
Use TNetHTTPClient with a HEAD request to a reliable endpoint (e.g., https://www.google.com or https://connectivitycheck.gstatic.com/generate_204). The async wrapper via TTask can remain unchanged.
Files Affected
lab-src/Lab*/forms/formMain.pas (connectivity check call site)
lab-src/Lab*/units/ (wherever Indy units are referenced)
All FieldLogger.dproj files (remove Indy package references if explicit)
Steps to Address
- Locate all
uses clauses referencing IdComponent, IdTCPClient, IdBaseComponent and remove them.
- Replace the connectivity check function body with:
uses System.Net.HttpClient;
function IsConnected: Boolean;
var
HTTP: THTTPClient;
Resp: IHTTPResponse;
begin
HTTP := THTTPClient.Create;
try
try
Resp := HTTP.Head('https://connectivitycheck.gstatic.com/generate_204');
Result := Resp.StatusCode < 500;
except
Result := False;
end;
finally
HTTP.Free;
end;
end;
- Wrap the call in
TTask.Run (or keep the existing TTask.Future<Boolean> wrapper) for async execution.
- Verify no other Indy units (
IdSSLOpenSSL, etc.) remain in the codebase.
- Remove explicit Indy package references from
.dproj files if present.
Test Plan
Overview
The training uses Indy (
IdTCPClient) solely to check internet connectivity by opening a TCP connection towww.embarcadero.com:80. Indy is a legacy networking library; Delphi has included the modernSystem.Net.HttpClientstack since XE8. The Indy dependency should be removed and replaced with a native connectivity check.Background
Current Pattern
This is wrapped in a
TTask.Future<Boolean>for async execution.Problems
System.Net.HttpClient(already used elsewhere in the project for the Maps API) achieves the same goal with a HEAD request and no extra dependency.Replacement Strategy
Use
TNetHTTPClientwith a HEAD request to a reliable endpoint (e.g.,https://www.google.comorhttps://connectivitycheck.gstatic.com/generate_204). The async wrapper viaTTaskcan remain unchanged.Files Affected
Steps to Address
usesclauses referencingIdComponent,IdTCPClient,IdBaseComponentand remove them.TTask.Run(or keep the existingTTask.Future<Boolean>wrapper) for async execution.IdSSLOpenSSL, etc.) remain in the codebase..dprojfiles if present.Test Plan
Id*.pasunit in theusesclause.Trueand the Maps API image loads.Falseand the app shows the "no internet" message gracefully.