1. Connect to a WebSocket server
Use TsgcWebSocketClient to connect to any RFC 6455 compliant server, send a message, and react to incoming frames.
uses
sgcWebSocket;
var
oClient: TsgcWebSocketClient;
begin
oClient := TsgcWebSocketClient.Create(nil);
try
oClient.URL := 'wss://echo.websocket.org';
oClient.WatchDog.Enabled := True; // auto-reconnect
oClient.OnMessage := procedure(Connection: TsgcWSConnection;
const Text: string)
begin
Writeln('Server says: ', Text);
end;
oClient.Active := True;
oClient.WriteData('Hello from Delphi!');
Readln;
finally
oClient.Free;
end;
end;
2. Generate a Delphi REST client from OpenAPI
Point TsgcOpenAPI_Generator at any OpenAPI 3 spec (local file or HTTP URL) and emit a typed Delphi client — classes, methods, auth, and request/response DTOs — in one call.
uses
sgcOpenAPI_Parser, sgcOpenAPI_Generator;
var
oGen: TsgcOpenAPI_Generator;
begin
oGen := TsgcOpenAPI_Generator.Create(nil);
try
oGen.Source := 'https://petstore3.swagger.io/api/v3/openapi.json';
oGen.OutputFolder := 'C:\Projects\PetStoreClient\src';
oGen.Language := lngDelphi;
oGen.Namespace := 'PetStore.Client';
oGen.Generate;
Writeln('Generated ', oGen.Files.Count, ' Delphi units');
finally
oGen.Free;
end;
end;
3. Sign a PDF
Use TsgcSignPDF to produce a PAdES-compliant signature with a certificate from any of the supported key providers (PKCS#11, Azure Key Vault, AWS KMS, Windows Cert Store, local PFX).
uses
sgcSign_PAdES, sgcSign_KeyProvider_Windows;
var
oSigner: TsgcSignPDF;
oKey : TsgcSign_KeyProvider_Windows;
begin
oKey := TsgcSign_KeyProvider_Windows.Create(nil);
oKey.CertificateThumbprint := 'a1b2c3d4...';
oSigner := TsgcSignPDF.Create(nil);
try
oSigner.KeyProvider := oKey;
oSigner.Profile := 'PAdES-B-LT';
oSigner.SignFile(
'C:\docs\contract.pdf',
'C:\docs\contract.signed.pdf');
Writeln('Signed: ', oSigner.LastSignatureId);
finally
oSigner.Free;
oKey.Free;
end;
end;