Intraweb Framework by delphicleancode/delphi-spec-kit
npx skills add https://github.com/delphicleancode/delphi-spec-kit --skill 'Intraweb Framework'Intraweb 是一个面向 Web 的 VCL 框架,它允许您以类似于创建桌面应用程序的语义化方式来创建有状态的业务 Web 应用程序。在 Copilot 或您的项目中处理 Intraweb 时,请遵循以下最佳实践以确保可维护性和可扩展性。
黄金法则: 请勿使用经典的单元 var 全局变量或单例实例来存储用户数据,因为 Intraweb 应用程序运行在多线程环境中,并存在并发会话(每个用户都有自己的会话)。
要维护用户特定的数据,请严格使用 UserSessionUnit.pas 单元(ServerController.UserSession 实例)。
//❌ 错误:不正确的用法(全局作用域变量服务于所有会话,存在多线程问题) var LCustomerId: Integer;
//✅ 正确:正确的用法(当前上下文的安全属性) UserSession.CustomerId := 10;
不依赖于用户的全局系统参数、数据库连接池和初始化操作必须在 ServerController (IWServerController.pas) 对象中解决。避免在 TIWAppForm 中注入重量级依赖项和直接的数据库作用域。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在 Web 上下文中,您不应使用阻塞代码来“等待”用户,例如 ShowMessage、InputBox 或依赖在同一行代码上锁定的经典 VCL ModalResults 调用。
使用 OnAsyncClick 属性来实现无需整页回发的 DOM 更新。
在 Intraweb 15 或更高版本中,探索 WebApplication.ShowMessage 结合 Ajax 调用和安全 Web 界面中断的能力。
//❌ 错误:在 Intraweb 上阻塞线程 procedure TIWForm1.iwBtnSaveClick(Sender: TObject); begin if Application.MessageBox('Deseja salvar?', 'Confirme', MB_YESNO) = IDYES then //Rescue code end;
//✅ 正确:使用 Intraweb 的 Ajax 异步调用 procedure TIWForm1.iwBtnSaveAsyncClick(Sender: TObject; EventParams: TStringList); begin WebApplication.ShowMessage('Registro Salvo via Callback Assíncrono!', smAlert); end;
在 Intraweb 中,很容易通过将所有系统规则都堆叠在点击事件背后(例如 iwBtnProcessarAsyncClick)来构建臃肿的项目。请遵循 SRP(单一职责原则):
IWApplication 单元(不要在持久化服务中使用 WebApplication.ShowMessage)。使用 iw 与原生类型名称连接:
TIWButton -> iwBtnSaveTIWEdit -> iwEdtNameTIWLabel -> iwLblTitleTIWComboBox -> iwCmbStatusTIWGrid -> iwGrdItemsTIWRegion -> iwRegContainer尽管 Intraweb 类似于 VCL,但在组件中进行大量样式化会在界面中创建庞大的 DOM。建议在表单中使用 ExtraHeader 注入来定义外部 CSS 文件,并将 Css 属性应用到 TIW* 可视化组件的标签上,而不是通过对象检查器手动设置按钮颜色和字体。
每周安装次数
–
代码仓库
GitHub 星标数
19
首次出现时间
–
安全审计
Intraweb is a VCL-for-the-Web framework that allows you to create stateful business web applications in a semantic way similar to creating Desktop applications. When dealing with Intraweb in Copilot or your project, consider the following best practices to ensure maintainability and scalability.
Golden Rule: Do not use classic unit var global variables or Singleton instances for user data, since Intraweb applications run in a Multithread environment with concurrent sessions (each user has their own).
To maintain user-specific data, strictly use the UserSessionUnit.pas unit (ServerController.UserSession Instance).
//❌ BAD: Incorrect Usage (Global scope variable serves all sessions, Multithreading problem) var LCustomerId: Integer;
//✅ GOOD: Correct Usage (Safe properties of the current context) UserSession.CustomerId := 10;
The global system parameters, database connection pool and initializations that do not depend on the user must be resolved in the ServerController (IWServerController.pas) object. Avoid injecting heavy dependencies and direct database scopes in TIWAppForm.
In the web context, you should not use blocking code to "wait" for the user, such as ShowMessage, InputBox, or classic VCL ModalResults calls that rely on code locking on the same line.
Use the OnAsyncClick property for DOM updates without full-screen postback.
In Intraweb version 15 or newer, explore the capabilities of WebApplication.ShowMessage combined with Ajax calls and safe web interface interrupts.
//❌ BAD: Blocking the thread on the Intraweb procedure TIWForm1.iwBtnSaveClick(Sender: TObject); begin if Application.MessageBox('Deseja salvar?', 'Confirme', MB_YESNO) = IDYES then //Rescue code end;
//✅ GOOD: Using Ajax Async from Intraweb procedure TIWForm1.iwBtnSaveAsyncClick(Sender: TObject; EventParams: TStringList); begin WebApplication.ShowMessage('Registro Salvo via Callback Assíncrono!', smAlert); end;
It is easy to build monstrous projects on the Intraweb by grouping the entire system rule behind the click (ex: num iwBtnProcessarAsyncClick). Follow the SRP (Single Responsibility Principle) principles:
IWApplication unit (do not use WebApplication.ShowMessage among persistence Services).Use iw concatenated with the native typologies:
TIWButton -> iwBtnSaveTIWEdit -> iwEdtNameTIWLabel -> iwLblTitleTIWComboBox -> iwCmbStatusTIWGrid -> iwGrdItemsTIWRegion -> Despite being VCL-like, the massive stylizations in the components create large DOMS in the interface. Prefer to define external CSS files using ExtraHeader injection in the form and apply the Css property to the tags of the T visual components TIW* instead of manually painting the color of buttons and fonts via the Object Inspector.
Weekly Installs
–
Repository
GitHub Stars
19
First Seen
–
Security Audits
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装
iwRegContainer