Usina BRAdvPL Guide
Sign in
← All topics
CLASSPublished

TDialog

TDialog():New( <nTop>, <nLeft>, <nBottom>, <nRight>, <cTitle>, ... )

Creates a dialog window to host visual components in AdvPL routines.

Visual interfaceClassesDialogsSmartClientTDialog
01 · OVERVIEW

Overview

TDialog is a visual class used to create dialog windows in SmartClient. It works as a container for components such as SAY, GET, BUTTON, CHECKBOX, BITMAP, BROWSE, FOLDER and panels. In a typical screen, the routine creates the dialog, adds components by informing their parent object and finally calls Activate() to display the window and hand control to the interface.

02 · SYNTAX

Syntax

TDialog():New( <nTop>, <nLeft>, <nBottom>, <nRight>, <cTitle>, ... )

Parameters

nTop, nLeft, nBottom, nRight
NumericRequired

Window coordinates. With PIXEL, they represent the pixel area used by SmartClient.

cTitle
CharacterRequired

Title displayed in the window bar.

Text/background colors
NumericOptional

Colors used in the window, usually supplied through color constants available in include files.

lPixels
LogicalOptional

Indicates that the provided measures should be interpreted as pixels.

Activate()
MethodRequired

Displays the dialog. Depending on the LIB version, it may receive options such as centering and an activation block.

03 · PRACTICAL EXAMPLE

Simple TDialog window

#Include "TOTVS.ch"

User Function ExTDialog()
    Local oDlg
    Local nHeight    := 180
    Local nWidth     := 360
    Local lUsePixels := .T.
    Local lCentered  := .T.
    Local bOnStart   := {|| ConOut("Dialog activated") }

    oDlg := TDialog():New(0, 0, nHeight, nWidth, ;
        "Screen using TDialog", , , , , , , , , lUsePixels)

    oDlg:Activate(, , , lCentered, , , bOnStart)
Return
Expected result

The dialog is created in memory and displayed centered. bOnStart is executed during activation.

04 · PRACTICAL EXAMPLE

TDialog as a component container

#Include "TOTVS.ch"

User Function ExTDialogCampos()
    Local oDlg
    Local cNome := Space(40)

    oDlg := TDialog():New(0, 0, 160, 380, "Cadastro rápido", , , , , , , , , .T.)

    @ 20, 20 Say "Nome:" Size 40, 10 Of oDlg Pixel
    @ 18, 65 Get cNome Size 140, 10 Of oDlg Pixel
    @ 50, 65 Button "Confirmar" Size 65, 14 ;
        Action MsgInfo("Olá, " + AllTrim(cNome)) Of oDlg Pixel

    oDlg:Activate(, , , .T.)
Return
Expected result

SAY, GET and BUTTON are created as children of oDlg. When the button is clicked, the ACTION block uses the typed value.

05 · PRACTICAL EXAMPLE

Declarative form with DEFINE DIALOG

#Include "TOTVS.ch"

User Function ExDefineDialog()
    Local oDlg

    Define Dialog oDlg Title "Exemplo declarativo" ;
        From 0, 0 To 160, 380 Pixel

    @ 25, 25 Say "Interface criada por comando" ;
        Size 150, 12 Of oDlg Pixel

    Activate Dialog oDlg Centered
Return
Expected result

DEFINE/ACTIVATE syntax is more declarative and is translated by the compiler into calls to the corresponding visual classes.

BEST PRACTICES
  • Use TDialog when you need a modal custom window for data entry, confirmation or information display.
  • Pass the dialog object as the parent of visual components, usually through the OF oDlg clause.
  • Keep screen construction in three clear steps: create the dialog, place the components and activate the window.
  • Prefer variable names that express the visual role of the object, such as oDlg, oGetName, oBtnConfirm and oSayStatus.
  • For complex screens, consider FWDefSize, FWLayer, MVC or framework components that help with organization and resizing.
COMMON PITFALLS
  • A modal dialog blocks interaction with the parent window while it is open; this is expected behavior.
  • Components without the correct parent may not appear or may be attached to the wrong active window.
  • Mixing pixel coordinates with another unit may cause alignment differences between environments.
  • Large ACTION blocks make maintenance harder; call helper functions instead.
  • Do not use TDialog as a substitute for MVC when the screen requires a data model, structured validations and integration with maintenance routines.

Related content

REFERENCES
  1. TOTVS. TDialog. TDN. Official reference for the TDialog visual class.
  2. Terminal de Informação. Creating screens with TDialog — AdvPL and TL++ Marathon 486. Published June 19, 2024.
  3. TOTVS. TWindow class: handling the parent screen while child screens are open. TOTVS Support Center, July 4, 2024.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha