sgcHTML in five minutes

sgcHTML turns Object Pascal into HTML. You build a page as a component tree, read one string property, and write that string to an HTTP response. This page does exactly that, then points you at the parts you will want next: forms, grids, charts and htmx.

Bootstrap 5 and htmx, server side
No JavaScript to write
Windows, Linux and macOS

What the first page needs

A page component that renders itself to a string, and an HTTP server to hand that string to a browser. Two objects.

The page component

TsgcHTMLComponent_Site, declared in sgcHTML_Component_Site.pas and registered on the SGC HTML palette page. It renders a whole shell: navigation, sidebar, theme and content.

The one property that matters

HTML, inherited from TsgcHTMLComponent. It is read-only, and reading it renders the current component tree to a complete HTML document.

The server

Anything that can write a string to an HTTP response. The shipped demo uses TsgcWSHTTPServer from sgcWebSocket_Server.pas when a Professional build is available, and falls back to TIdHTTPServer otherwise.

Platforms

Desktop and server only. SGC_HTML is defined inside {$IFNDEF ANDROID} and {$IFNDEF IOS}, so on mobile every sgcHTML unit compiles to nothing. Windows, macOS and Linux are all fine.

Requirements and editions

The edition column is the define that gates the code, with the line it sits on in Source/sgcVer.inc.

What Value
IDE Delphi 7 through RAD Studio 13, and C++Builder 2007 through 13. Lazarus is supported as well, and an ERP demo ships that has been run on Linux.
Uses clause sgcHTML_Component_Site for the page shell, plus the node units you actually use, for example sgcHTML_Nodes, sgcHTML_Nodes_Bootstrap, sgcHTML_Nodes_Table, sgcHTML_Nodes_Forms and sgcHTML_Nodes_Charts.
Pack define SGC_PACK_HTML is defined on line 871, inside the {$IFDEF SGC_EDT_ALL} block that runs from line 870 to line 874. In the sgcWebSockets source tree that means the All-Access edition turns it on. sgcHTML is also sold as its own product with its own installer and its own licence.
Feature defines Inside the {$IFDEF SGC_PACK_HTML} block on lines 882 to 892: SGC_HTML on line 885 and SGC_HTMX on line 886, both inside {$IFNDEF ANDROID} at 883 and {$IFNDEF IOS} at 884. SGC_HTML_CONTROL, the design-time visual surface, is on line 888 inside {$IFDEF MSWINDOWS} at 887.
What that means on mobile Every sgcHTML unit wraps its interface in {$IFDEF SGC_HTML}, so an Android or iOS build compiles them to empty units. This is a server-side library, which is the point: the phone gets HTML, not Pascal.
Registration The palette page is registered only when both SGC_PACK_HTML and SGC_HTML are defined.

Which components exist? Around eighty, from a grid and a scheduler to charts, a rich editor, a QR code and a camera scanner. The feature matrix groups them by area, and each has its own page under components.

Install and find the palette page

sgcHTML ships as its own package and also inside the All-Access build of sgcWebSockets. The install is the same shape.

1. Unzip

Unzip the download to a folder, called {$DIR} below.

2. Library path

Tools, Options, Library. Add {$DIR}\source and the lib folder for your IDE, for example {$DIR}\libD13\$(Platform).

3. Build the packages

Open the package group for your IDE version under {$DIR}\Packages\. Compile the runtime .dpk first, then install the design-time dcl one. Lazarus uses the .lpk instead.

4. Check the palette

A page called SGC HTML appears, holding around eighty components. If it is missing on an Android or iOS target that is expected, because SGC_HTML is excluded there.

5. Run a demo first

Open {$DIR}\Demos\60.HTML\01.RunTime\07.Site, build it and run it. It is a console server, it prints its own URL, and it is where the code below comes from.

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.

sgcSiteDemo_Pages.pas
uses
  SysUtils, Classes,
  // sgc
  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>');

    // reading HTML is what runs the render
    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.

sgcSiteDemo_Server.pas
uses
  SysUtils, Classes,
  // sgc
  sgcWebSocket_Server,
{$IFDEF SGC_INDY}
  sgcIdContext, sgcIdCustomHTTPServer;
{$ELSE}
  IdContext, IdCustomHTTPServer;
{$ENDIF}

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.

sgcSiteDemoServer.dpr
program sgcSiteDemoServer;

{$APPTYPE CONSOLE}

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.

All three tabs come from the shipped demo Demos\60.HTML\01.RunTime\07.Site, trimmed to the parts that matter. The full project also switches layout, theme and colour scheme from the query string, which is worth reading once the first page renders.

Confirm the page rendered

The program prints the URL it is listening on. Open it, and then try the switches.

The URL it prints

The program writes http://localhost:8092 to the console on startup. Open it. A page with navigation, a sidebar and your content means the render and the server are both working.

Active

FHTTP.Active := True either succeeds or raises. If something else already owns port 8092 you find out here.

The content type

A browser that shows raw markup instead of a page means the response went out without text/html. Set ContentType before assigning ContentText.

Switch a layout

The shipped demo reads layout, theme and mode from the query string, so ?layout=topnav&mode=dark re-renders the same page a different way. That is the fastest way to see what the component does.

What usually goes wrong the first time

Six problems account for nearly every first attempt that does not render.

The palette page never appears

Registration needs both SGC_PACK_HTML and SGC_HTML. The first is defined on line 871 inside the All-Access block, the second on line 885 inside the pack block. On an Android or iOS target the second is deliberately absent.

The page is blank

You built the tree but never read HTML. That property is what runs the render. Reading it is the whole rendering step, and it returns a complete document, not a fragment.

Nothing changes when you edit the page

The demo builds a fresh TsgcHTMLComponent_Site on every request and frees it afterwards. If you cache the object and reuse it, remember to clear its content with ClearContent before rebuilding.

The browser shows raw markup

The response content type was never set. The demo sets ContentType := 'text/html; charset=utf-8' before writing the body, and without it some clients will display the HTML as text.

You are writing HTML strings by hand

You do not have to. There are node units for Bootstrap layout, tables, forms and charts, and the whole point of the library is that you compose those instead of concatenating markup.

The port is already taken

The demo listens on 8092. If something else owns that port the server will not start, so change the port before you go looking for a deeper problem.

What people build after the first page

Four directions, all inside the same package.

Forms that post back

The forms node unit builds inputs, selects, validation and layout, and htmx posts them without a page reload. Escaping is handled for you when you build nodes rather than strings.

Form components

Data on the page

A grid with sorting, filtering and paging, plus charts, stat cards, a scheduler, a Gantt chart and a diagram component.

Feature matrix

Whole applications

Twelve runtime demos ship, from an ERP dashboard to a point of sale, a helpdesk, a warehouse and a field service app. They are the fastest way to see the library at real scale.

Demo gallery

Bring your existing web tier

There are components for WebBroker and DataSnap, so an existing Delphi web application can render sgcHTML pages without being rewritten.

WebBroker and DataSnap

Reference, demos and documentation

The catalogue lists every component with a preview. Demo projects ship inside the download, under Demos\60.HTML.

TsgcHTMLComponent_Site page The page shell this quick start builds on, property by property.
Feature matrix Layout, forms, data, charts, auth, chat and the rest, grouped by area.
Demo gallery The shipped runtime demos, each with a short video.
WebBroker and DataSnap Rendering sgcHTML pages from an existing Delphi web tier.
Download the trial The same installer as production, time limited.
Online help The generated reference, always in step with the current release.

Related reading: the Site component, web UI components in Delphi, smarter forms and data tables. Every product has its own quick start, listed on the getting started page.

sgcHTML quick start questions

TsgcHTMLComponent_Site, from the unit sgcHTML_Component_Site.pas. It renders a complete page shell, so you get navigation, a sidebar, a theme and a content area without assembling them yourself. Build it, call AddMenu and AddContent or AddSection, then read the HTML property. The shipped Site demo does exactly that.
You write it to an HTTP response yourself. HTML is a plain string property, so any server will do. The shipped demo uses TsgcWSHTTPServer on a Professional build and falls back to TIdHTTPServer otherwise, sets ResponseNo := 200 and ContentType := 'text/html; charset=utf-8', and assigns the string to ContentText.
The gate is SGC_PACK_HTML, defined on line 871 of sgcVer.inc, inside the {$IFDEF SGC_EDT_ALL} block that runs from line 870 to line 874. In that source tree the All-Access edition is what defines it. sgcHTML is also sold as its own product with its own installer, so check the sgcHTML pricing page for the current bundles rather than inferring it from the define.
No, and that is deliberate. SGC_HTML is defined on line 885 inside {$IFNDEF ANDROID} at line 883 and {$IFNDEF IOS} at line 884, so on those targets every sgcHTML unit compiles to an empty unit. It is a server-side library: the phone receives HTML over the network, which is why the mobile target does not need the renderer. Windows, macOS and Linux are all supported.
No. The library emits Bootstrap 5 markup and htmx attributes, and htmx is what makes a button post back and swap part of the page without a reload. You describe the interaction in Pascal and the attributes are generated for you. You can still add your own script when you want to, through CustomHead and BodyEndHTML.
Yes. Layout takes a TsgcHTMLSiteLayout, whose members are slSidebarLeft, slSidebarRight, slTopNav, slTopNavSidebarLeft, slIconRail and slOffcanvas, and it defaults to slTopNavSidebarLeft. Preset takes a TsgcHTMLSitePreset with members including spAdmin, spDashboard, spPortal, spDocs, spLanding and spApp. Colours and light or dark mode live on the Theme object.
When you build the page as nodes, yes, because the node writes the text and escapes it. The risk appears when you bypass the nodes and concatenate markup yourself, for example through AddContent with a string you built from user input. Prefer the node units for anything that carries user data.
The download ships seventeen runtime demos under Demos\60.HTML\01.RunTime, including an ERP dashboard, a helpdesk, a point of sale, a warehouse, a reports app and a field service app. The gallery has a short video of each.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to build a web UI in Pascal?

Download the trial and run the Site demo before you write a line of markup.