五分钟上手 sgcUI

sgcUI 是适用于 Delphi、C++Builder 和 .NET 的十四款原生界面产品,由一个安装程序统一安装。本页将安装试用版,在窗体上放置一个带实时数据行的表格,展示 C++Builder 和 C# 中的相同代码,然后各用一次调用将整个应用程序切换为深色模式和从右到左布局。

一个安装程序,14 款产品
VCL、FireMonkey、WinForms、WPF 和 Avalonia
内置深色主题和从右到左布局

安装试用版

每个产品没有单独的安装程序。一个 Delphi 试用版和一个 C++Builder 试用版即可安装全部十四款产品,.NET 版本则来自 NuGet。

1. 运行安装程序

下载试用版(Delphi 或 C++Builder)并运行。试用版会安装每款产品的试用版本,包含演示和帮助,无需许可证。

2. 选择您的 IDE

选择要安装到的 Delphi 或 C++Builder 版本,从 Delphi 7 和 C++Builder 2007 直至 RAD Studio 13。安装程序会为每个版本编译包,并在 IDE 中注册设计时包。

3. 依赖项自动处理

sgcGrid、sgcCharts、sgcDashboard 及其他控件构建在 sgcUICore 之上,sgcReports 则构建在 sgcPDF 之上。安装程序会按此顺序编译,因此无需手动添加任何内容。

4. 检查组件面板

每个产品都有自己的组件面板页: SGC Grid, SGC Navigation, SGC Toolbar, SGC Editors, SGC Charts, SGC Dashboard, SGC Gauges, SGC PivotGrid, SGC Planner, SGC Diagram, SGC Wizard, SGC Maps, sgcPDF 和 sgcReports。

5. 通过 NuGet 获取 .NET 版本

为您的界面框架添加相应的包,例如 esegece.sgcGrid.WinForms、esegece.sgcGrid.Wpf 或 esegece.sgcGrid.Avalonia。它会自动引入 esegece.sgcGrid 和 esegece.sgcUICore。

6. Community 版或注册版

每个 .NET 产品还提供带有 .Community 后缀的免费 Community 包,例如 esegece.sgcGrid.Community。注册版包则包含全部功能、完整源代码和商业许可证。

您的第一个 sgcUI 窗体

创建一个 VCL 应用程序,将 SGC Grid 面板页中的 TsgcVCLGrid 拖到窗体上,双击窗体生成 FormCreate,然后输入下面的代码。按 F9 运行。C++Builder 和 .NET WinForms 应用程序中的相同表格见其他选项卡。

Unit1.pas
uses
  SysUtils, Classes, Controls, Forms,
  sgcGrid_Columns, sgcGrid_Data, sgcGrid_VCL;

type
  TForm1 = class(TForm)
    sgcVCLGrid1: TsgcVCLGrid;
    procedure FormCreate(Sender: TObject);
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  sgcVCLGrid1.Align := alClient;
  // the columns: field name, caption and data type
  sgcVCLGrid1.Columns.Add('Symbol', 'Symbol');
  sgcVCLGrid1.Columns.Add('Price', 'Price', gdtFloat).DisplayFormat := '0.00';
  sgcVCLGrid1.Columns.Add('Volume', 'Volume', gdtInteger);
  // one row per key, the values in column order
  sgcVCLGrid1.Data.AppendRow('MSFT', ['MSFT', 412.5, 1200]);
  sgcVCLGrid1.Data.AppendRow('AAPL', ['AAPL', 228.1, 3400]);
  // later, from any thread: update a row by key and field name
  sgcVCLGrid1.Data.UpdateRow('MSFT', ['Price', 'Volume'], [413.1, 1350]);
end;

AppendRow 按列顺序接收各个值。UpdateRow 接收字段名,因此只携带价格的消息只会更新价格,而尚不存在的键则会被插入。也可以在设计时使用 Columns 编辑器添加列,同一面板页中的 TsgcGridSource_DataSet 可以从任意 TDataSet 填充表格。

Unit1.cpp
#include <vcl.h>
#include "sgcGrid_Columns.hpp"
#include "sgcGrid_Data.hpp"
#include "sgcGrid_VCL.hpp"

void __fastcall CreateGrid(TForm *Form)
{
  TsgcVCLGrid *Grid = new TsgcVCLGrid(Form);
  Grid->Parent = Form;
  Grid->Align = alClient;
  // the columns: field name, caption and data type
  Grid->Columns->Add("Symbol", "Symbol", gdtText);
  Grid->Columns->Add("Price", "Price", gdtFloat)->DisplayFormat = "0.00";
  Grid->Columns->Add("Volume", "Volume", gdtInteger);
  // one row per key, the values in column order
  Grid->Data->AppendRow("MSFT", OPENARRAY(Variant,
    (Variant("MSFT"), Variant(412.5), Variant(1200))));
  Grid->Data->AppendRow("AAPL", OPENARRAY(Variant,
    (Variant("AAPL"), Variant(228.1), Variant(3400))));
}

C++Builder 通过 C++Builder 安装程序生成的头文件和库使用相同的组件。Delphi 开放数组使用 OPENARRAY 宏传递。也可以不写代码,直接将 TsgcVCLGrid 放到窗体上,在对象检查器中设置列。

Program.cs
// dotnet add package esegece.sgcGrid.WinForms
using System;
using System.Windows.Forms;
using esegece.sgcGrid;

internal static class Program
{
    [STAThread]
    private static void Main()
    {
        Application.EnableVisualStyles();
        Form oForm = new Form { Text = "My first sgcUI form", Width = 640, Height = 360 };

        TsgcWinFormsGrid oGrid = new TsgcWinFormsGrid { Dock = DockStyle.Fill };
        oGrid.Columns.Add("symbol", "Symbol");
        oGrid.Columns.Add("price", "Price", TsgcGridDataType.gdtFloat).DisplayFormat = "0.00";
        oGrid.Columns.Add("volume", "Volume", TsgcGridDataType.gdtInteger);
        oGrid.Data.AppendRow("MSFT", "MSFT", 412.5, 1200);
        oGrid.Data.AppendRow("AAPL", "AAPL", 228.1, 3400);
        oGrid.Data.UpdateRow("MSFT", new[] { "price", "volume" }, new object[] { 413.1, 1350 });
        oForm.Controls.Add(oGrid);

        Application.Run(oForm);
    }
}

类名沿用 Delphi 的命名:WinForms 使用 TsgcWinFormsGrid,WPF 使用 TsgcWpfGrid,且各自都有相同的 Columns 和 Data 成员。WinForms 包面向 .NET Framework 4.7.2 以及适用于 Windows 的 .NET 8、9 和 10。

整个应用程序一个开关

每个 sgcUI 控件默认都遵循应用程序的主题和方向。一次调用即可将它们全部以深色模式重绘,另一次调用则可为阿拉伯语或希伯来语镜像整个应用程序。

Theme.pas
uses
  Classes,
  sgcUICore_Theme, sgcUICore_Theme_VCL;

procedure ApplyAppSettings(aDark, aRightToLeft: Boolean);
begin
  // every sgcUI control whose Theme is utDefault repaints in the new theme;
  // True also themes the standard controls of every open form
  if aDark then
    sgcUISetApplicationTheme(utDark, True)
  else
    sgcUISetApplicationTheme(sgcUISystemTheme, True);
  // mirrors every open form and the sgcUI controls that follow it
  if aRightToLeft then
    sgcUISetApplicationBiDiMode(bdRightToLeft)
  else
    sgcUISetApplicationBiDiMode(bdLeftToRight);
end;

这两个函数都位于 sgcUICore_Theme 中。传入 True 时,请添加 sgcUICore_Theme_VCL(或 sgcUICore_Theme_FMX),这样窗体上的标准控件也会应用主题。sgcUISystemTheme 返回操作系统的浅色或深色选择。在 C++Builder 中,包含 sgcUICore_Theme.hpp 并进行相同的调用。自身 Theme 为 utLight、utDark 或 utCustom 的控件会保持该设置。

Program.cs
using esegece.sgcUICore;

// follow the light or dark choice of Windows, and theme the forms too
sgcUIApplication.SetTheme(sgcUIApplication.SystemTheme(), true);

// or force dark mode
sgcUIApplication.SetTheme(TsgcUITheme.utDark);

// mirror every open form and the sgcUI controls that follow it
sgcUIApplication.SetRightToLeft(true);

sgcUIApplication 是 esegece.sgcUICore 中的静态类,由 WinForms、WPF 和 Avalonia 共用。对于单个控件,标准属性仍然有效:WinForms 中为 RightToLeft,WPF 和 Avalonia 中为 FlowDirection。

演示、产品和文档

套件演示是同时使用多款产品的完整应用程序。演示源代码随试用版提供,位于 Demos\Suite 下。

套件演示 ERP、Factory、Fleet、Markets 和 Portfolio,已编译,可直接运行。
14 款产品 标准版:sgcGrid、sgcNavigation、sgcToolbar 和 sgcEditors。专业版增加 sgcCharts、sgcDashboard 和 sgcGauges。企业版增加 sgcPivotGrid、sgcPlanner、sgcDiagram、sgcWizard、sgcMaps、sgcPDF 和 sgcReports。
功能对比 并排展示每款产品在 Delphi、C++Builder 和 .NET 中的功能。
在线帮助 安装、按产品和框架划分的快速入门、应用程序主题以及从右到左布局。
定价 标准版、专业版和企业版,或任意单个产品。
下载试用版 Delphi 和 C++Builder 安装程序、已编译的演示以及 NuGet 包列表。

每款产品都有自己的快速入门,列在入门页面上。

sgcUI 快速入门常见问题

不需要。一个安装程序涵盖全部十四款产品。试用版会安装每款产品,而正式安装程序会为每个产品显示一个复选框,并启用您的许可证所拥有的产品。依赖其他产品的产品(例如依赖 sgcPDF 的 sgcReports)会自动一并安装。
从与您的界面最匹配的那个开始。大多数应用程序先用 sgcGrid 处理数据,再添加 sgcCharts 或 sgcDashboard 用于可视化,并用 sgcNavigation 和 sgcToolbar 构建应用外壳。由于它们共用 sgcUICore,因此共享同一个主题和同一个方向。
模型是相同的,只是控件类不同:FireMonkey 使用 TsgcFMXGrid,WPF 使用 TsgcWpfGrid,Avalonia 使用 TsgcAvaloniaGrid,它们都有相同的 Columns 和 Data。帮助中为每个产品和每个框架都提供了快速入门。
超值之选:All-AccesseSeGeCe 全部产品,含高级支持,每年 €1,059 起。
查看 All-Access 价格

准备好构建您的第一个 sgcUI 窗体了吗?

下载试用版,运行套件演示,然后在窗体上放置一个表格。