QuickStart
A page in Pascal, served over HTTP
Build the page, read the HTML property, write it to the response. The first tab is the page, the second is the server, the third is the whole console program.
uses
SysUtils, Classes,
sgcHTML_Component_Site;
class function TsgcSiteDemoPages.BuildPage: string;
var
oSite: TsgcHTMLComponent_Site;
begin
oSite := TsgcHTMLComponent_Site.Create(nil);
try
oSite.Title := 'sgcHTML Site Layouts';
oSite.Layout := slSidebarLeft;
oSite.AddMenu('Dashboard', '/');
oSite.AddMenu('Customers', '/?page=customers');
oSite.AddSection('Welcome', '<p>Served from Delphi.</p>');
Result := oSite.HTML;
finally
oSite.Free;
end;
end;
Layout takes a TsgcHTMLSiteLayout: slSidebarLeft, slSidebarRight, slTopNav, slTopNavSidebarLeft, slIconRail or slOffcanvas. The default is slTopNavSidebarLeft, so the line above is only there to show the switch.
uses
SysUtils, Classes,
sgcWebSocket_Server,
sgcIdContext, sgcIdCustomHTTPServer;
IdContext, IdCustomHTTPServer;
constructor TsgcSiteDemoServer.Create;
begin
inherited Create;
FPort := 8092;
FHTTP := TsgcWSHTTPServer.Create(nil);
FHTTP.Port := FPort;
FHTTP.OnCommandGet := HandleCommandGet;
end;
procedure TsgcSiteDemoServer.Start;
begin
FHTTP.Active := True;
end;
procedure TsgcSiteDemoServer.SendHTML(AResponseInfo: TIdHTTPResponseInfo;
const aHTML: string);
begin
AResponseInfo.ResponseNo := 200;
AResponseInfo.ContentType := 'text/html; charset=utf-8';
AResponseInfo.ContentText := aHTML;
end;
The Indy units are conditional because a build with the custom Indy library sees them as sgcIdContext and sgcIdCustomHTTPServer, and a build on stock Indy as IdContext and IdCustomHTTPServer. The shipped demo carries exactly that conditional. Any server that can write a string will do. The shipped demo picks TsgcWSHTTPServer when a Professional build is available and falls back to TIdHTTPServer otherwise, which is why the demo has a conditional there and this excerpt does not.
program sgcSiteDemoServer;
uses
SysUtils,
sgcSiteDemo_Server in 'sgcSiteDemo_Server.pas',
sgcSiteDemo_Pages in 'sgcSiteDemo_Pages.pas';
var
oServer: TsgcSiteDemoServer;
begin
oServer := TsgcSiteDemoServer.Create;
try
oServer.Start;
WriteLn('sgcHTML Site Layouts Demo - http://localhost:' +
IntToStr(oServer.Port));
WriteLn('Press Enter to stop.');
ReadLn;
oServer.Stop;
finally
oServer.Free;
end;
end.
A console application, so there is no form and no VCL to set up. That is the shortest possible sgcHTML program, and it is what the shipped demo actually is.