### Example of DBNickIndexKey usage Source: https://tdn.totvs.com.br/display/tec/DBNickIndexKey Demonstrates creating a table, defining an index, assigning a nickname to that index, and retrieving the key using DBNickIndexKey. ```AdvPL FUNCTION Example() Local cT1 := "T1" TCLink() DBCreate("T1", {{"FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}, ; {"FIELD_AGE", "C", 10, 0}, ; {"FIELD_NICK", "C", 10, 0}, ; {"FIELD_COL", "C", 10, 0}}, "TOPCONN") DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .T.) (cT1)->(DBCreateIndex('T1_IND', 'FIELD_NAME', { || 'FIELD_NAME' })) (cT1)->(DBSetNickname("T1_IND", "T1_NICKNAME")) conout((cT1)->(DBNickIndexKey("T1_NICKNAME"))) DBCloseArea() TCUnlink() RETURN ``` -------------------------------- ### Verify Table and Index Existence with TCCanOpen Source: https://tdn.totvs.com.br/display/tec/TCCanOpen This example demonstrates creating tables and indexes, then using TCCanOpen to check their existence. It includes scenarios for both existing and non-existing database objects. ```AdvPL STATIC Function CreateTable() TCDelFile('T1') TCDelFile('T2') DBCreate('T1', {{"FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}}, 'TOPCONN') DBCreate('T2', {{"FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}, ; {"FIELD_ID", "N", 3, 0}}, 'TOPCONN') RETURN FUNCTION u_canOpen() TCLink() CreateTable() DBUseArea(.F., 'TOPCONN', 'T2', 'T2', .F., .F.) DBCreateIndex('T2_IND', 'FIELD_NAME', { || 'FIELD_NAME' }) IIF(TCCanOpen('T1'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .T., ou seja, tabela existe IIF(TCCanOpen('T2'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .T., ou seja, tabela existe IIF(TCCanOpen('T3'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .F., ou seja, tabela não existe IIF(TCCanOpen('T2', 'T2_IND'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .T., ou seja, tabela e índice existem IIF(TCCanOpen('T2', 'T2_INDEX'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .F., pois, o índice T2_INDEX não existe IIF(TCCanOpen('T1', 'T1_IND'), CONOUT('TRUE'), CONOUT('FALSE')) // retorna .F., pois, o índice T1_IND não existe DBCloseArea() RETURN ``` -------------------------------- ### Toggle TMailMng lUseRealID Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AlUseRealID This example demonstrates how to instantiate TMailMng and toggle its lUseRealID property, showing the change in output. ```protheus Local oServer := TMailMng():New( 1 ) conout( oServer:lUseRealID ) // Vai exibir ".F." oServer:lUseRealID := .T. conout( oServer:lUseRealID ) // Vai exibir ".T." ``` -------------------------------- ### Create and Query TOPCONN Database Table Source: https://tdn.totvs.com.br/display/tec/DBGoTo This example demonstrates creating a new database table 'T1' with specified fields, inserting data using the U_insert function, and then querying a specific record. It checks if FIELD_AGE matches '222'. Ensure TCLink and DBCreate are called before data operations and TCUnlink after. ```advpl FUNCTION Example() Local cT1 := "T1" TCLink() DBCreate("T1", {{'FIELD_NAME', 'C', 10, 0}, ; {"FIELD_TYPE", 'C', 10, 0}, ; {"FIELD_AGE", 'C', 10, 0}, ; {"FIELD_NICK", 'C', 10, 0}, ; {"FIELD_COL", 'C', 10, 0}}, "TOPCONN") U_insert() DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .T.) (cT1)->(DBGoTo(2)) IF ((cT1)->FIELD_AGE == "222 ") conout("Found!") ENDIF DBCloseArea() TCUnlink() RETURN ``` -------------------------------- ### Add Contact Example Source: https://tdn.totvs.com.br/display/tec/TMobile%3AAddContact This snippet demonstrates how to create a new contact and add it using the TMobileContact class. Ensure the TMobileContact class is properly initialized. ```AdvPL oContact := TMobileContact():New() oContact:cName := "Nome Teste" ConOut( oMbl:AddContact( oContact ) ) ``` -------------------------------- ### Set and Get CSS for an Object Source: https://tdn.totvs.com.br/display/tec/TSrvObject%3AGetCSS This snippet shows how to set a CSS style for an object and then retrieve it. Ensure the object is properly initialized before use. ```Totvs oObject:SetCSS("CSS { border: 1px solid #000000 }") ConOut("CSS: " + oObject:GetCSS()) ``` -------------------------------- ### Instantiate and Use TMailMng Object Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AnSMTPSSL Instantiates the TMailMng object and accesses its nSMTPSSL property. This example demonstrates basic object creation and property access. ```advpl Local oServer := TMailMng():New( 0, 3, 6 ) conout( oServer:nSMTPSSL ) // Vai exibir "6" ``` -------------------------------- ### Set Text Size Source: https://tdn.totvs.com.br/display/tec/TSimpleEditor%3ATextSize Sets the size of the text. No specific setup or imports are mentioned for this function. ```javascript oEdit:TextSize( 26 ) ``` -------------------------------- ### Test Device Feature Availability Source: https://tdn.totvs.com.br/display/tec/TMobile%3ATestDevice Example usage of the TestDevice method to check for location feature availability. ```AdvPL lOk := oMbl:TestDevice(LOCATION_FEATURE) ``` -------------------------------- ### Set SpinBox Step Value Source: https://tdn.totvs.com.br/display/tec/TSpinBox%3AsetStep Use this to set the increment/decrement value for a spin box. This example sets the step to 30. ```totvs oSpinBox:SetStep( 30 ) ``` -------------------------------- ### Clear Grid Rows Source: https://tdn.totvs.com.br/display/tec/TGrid%3AClearRows Use this function to clear all rows from a grid. No specific setup or imports are mentioned. ```javascript oGrid:ClearRows() ``` -------------------------------- ### Initialize and Configure TMailMng Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AnSrvTimeout Demonstrates how to instantiate TMailMng, set server properties, and manage timeout values. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:nSrvTimeout ) // Vai exibir "30" oServer:nSrvTimeout := 40 conout( oServer:nSrvTimeout ) // Vai exibir "40" oServer:cSrvAddr := "mail.totvs.com.br" oServer:cUser := "totver" oServer:cPass := "mypass" oServer:Connect() oServer:nSrvTimeout := 60 conout( oServer:nSrvTimeout ) // Vai exibir "40" ``` -------------------------------- ### Initialize TMailMng and manage lKeepMsg Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AlKeepMsg Demonstrates how to instantiate the TMailMng class and toggle the lKeepMsg property. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) ``` ```AdvPL conout( oServer:lKeepMsg ) ``` ```AdvPL // Vai exibir ".F." ``` ```AdvPL oServer:lKeepMsg := ".T." ``` ```AdvPL conout( oServer:lKeepMsg ) ``` ```AdvPL // Vai exibir ".T." ``` -------------------------------- ### Set Current Group for Panel Source: https://tdn.totvs.com.br/display/tec/TToolBox%3AsetCurrentGroup Use this to set the current group for a specific panel. No specific setup or imports are mentioned. ```AdvPL oTb:SetCurrentGroup( oPanel1 ) ``` -------------------------------- ### Initialize and Configure TMailMng Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AnSrvPort Demonstrates creating a TMailMng instance and modifying its server port and connection properties. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:nSrvPort ) // Vai exibir "995" oServer:nSrvPort := 996 conout( oServer:nSrvPort ) // Vai exibir "996" oServer:cSrvAddr := "mail.totvs.com.br" oServer:nSrvPort := 995 oServer:cUser := "totver" oServer:cPass := "mypass" oServer:Connect() oServer:nSrvPort := 997 conout( oServer:nSrvPort ) // Vai exibir "995" ``` -------------------------------- ### Configure and Connect TMailMng with SSL Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AlSrvRetrySSL This snippet demonstrates how to instantiate TMailMng, set SSL retry, user credentials, and connect to the server. It also shows how to check the SSL retry status before and after connection. ```Protheus Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:lSrvRetrySSL ) // Vai exibir ".F." oServer:lSrvRetrySSL := .T. oServer:cUser := "totver" oServer:cPass := "mypass" oServer:Connect() conout( oServer:lSrvRetrySSL ) // Vai exibir ".T." oServer:lSrvRetrySSL := .F. conout( oServer:lSrvRetrySSL ) // Vai exibir ".T." ``` -------------------------------- ### Connect and Retrieve Email with TMailMng Source: https://tdn.totvs.com.br/display/tec/Classe%2BTMailMng Demonstrates initializing a mail manager, setting credentials, connecting to an IMAP server, and receiving a message. It also includes error handling for connection and authentication steps. ```AdvPL #define POP3 0 #define IMAP 1 #define MAPI 2 user Function mail1() Local oServer Local oMessage Local xRet Local nNumMsg := 0 oMessage := TMailMessage():New() oServer := TMailMng():New( IMAP, 3, 6 ) conout( "Protocol: " + cValToChar( oServer:nProtocol ) ) conout( "Verbose: " + cValToChar( oServer:lVerbose ) ) conout( "Keep Message: " + cValToChar( oServer:lKeepMsg ) ) conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) conout( "Username: " + oServer:cUser ) conout( "Password: " + oServer:cPass + CRLF ) conout( "Server SSL Version: " + cValToChar( oServer:nSrvSSL ) ) conout( "Server SSL Retry: " + cValToChar( oServer:lSrvRetrySSL ) ) conout( "Server Address: " + oServer:cSrvAddr ) conout( "Server Port: " + cValToChar( oServer:nSrvPort ) ) conout( "Server Timeout: " + cValToChar( oServer:nSrvTimeout ) + CRLF ) conout( "SMTP SSL Version: " + cValToChar( oServer:nSMTPSSL ) ) conout( "SMTP SSL Retry: " + cValToChar( oServer:lSMTPRetrySSL ) ) conout( "SMTP Address: " + cValToChar( oServer:cSMTPAddr ) ) conout( "SMTP Port: " + cValToChar( oServer:nSMTPPort ) ) conout( "SMTP Timeout: " + cValToChar( oServer:nSMTPTimeout ) + CRLF ) conout( "SMTP Localhost: " + oServer:cSMTPLocalhost ) conout( "Auth Login: " + cValToChar( oServer:lAuthLogin ) ) conout( "Auth NTLM: " + cValToChar( oServer:lAuthNTLM ) ) conout( "Auth Plain: " + cValToChar( oServer:lAuthPlain ) ) conout( "Extend SMTP: " + cValToChar( oServer:lExtendSMTP ) + CRLF ) oServer:cUser := "totvsuser" oServer:cPass := "totvspassword" oServer:cSrvAddr := "mail.totvs.com.br" oServer:cSMTPAddr := "mail.totvs.com.br" conout( "Server Address: " + oServer:cSrvAddr ) conout( "Server Port: " + cValToChar( oServer:nSrvPort ) ) conout( "Server Timeout: " + cValToChar( oServer:nSrvTimeout ) + CRLF ) conout( "SMTP Address: " + cValToChar( oServer:cSMTPAddr ) ) conout( "SMTP Port: " + cValToChar( oServer:nSMTPPort ) ) conout( "SMTP Timeout: " + cValToChar( oServer:nSMTPTimeout ) + CRLF ) // Make IMAP connection xRet := oServer:Connect() if xRet != 0 conout( "Error on Connect: " + oServer:GetErrorString( xRet ) ) return endif conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) // Get number of messages xRet := oServer:GetNumMsgs( @nNumMsg ) if xRet <> 0 conout( "Error on GetNumMsgs: " + oServer:GetErrorString( xRet ) ) oServer:Disconnect() return endif conout( "Number of messages: " + cValToChar( nNumMsg ) + CRLF ) if nNumMsg > 0 conout( "Receiving message 1" ) // Receives the first message xRet := oMessage:Receive2( oServer, 1 ) if xRet != 0 conout( "Error on Receive2: " + oServer:GetErrorString( xRet ) ) oServer:Disconnect() return endif conout( "Message 1 received!" ) conout( "From: " + oMessage:cFrom ) conout( "To: " + oMessage:cTo ) conout( "Date: " + oMessage:cDate ) conout( "Subject: " + oMessage:cSubject ) conout( "Body: " + oMessage:cBody ) conout( "Number of attachments: " + cValToChar( oMessage:GetAttachCount() ) + CRLF ) endif // Disconnect from IMAP server xRet := oServer:Disconnect() if xRet <> 0 conout( "Error on Disconnect: " + oServer:GetErrorString( xRet ) ) return endIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) // Make SMTP connection xRet := oServer:SMTPConnect() if xRet <> 0 conout( "Error on SMTP Connect: " + oServer:GetErrorString( xRet ) ) return endIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) // Authenticate with the wrong credentials xRet := oServer:SMTPAuth( "user", "pass" ) if xRet <> 0 conout( "Error on SMTP Auth: " + oServer:G ``` -------------------------------- ### Get Selected Text Source: https://tdn.totvs.com.br/display/tec/TSimpleEditor%3ARetTextSel Use this function to retrieve the currently selected text in the editor. Ensure the editor is in a state where text can be selected. ```totvs oEdit:RetTextSel() // Result: "Texto selecionado" ``` -------------------------------- ### Set WebEngine as Main Source: https://tdn.totvs.com.br/display/tec/TWebEngine%3ASetAsMain Configures the specified WebEngine instance as the primary component. ```AdvPL oWebEngine:SetAsMain() ``` -------------------------------- ### Initialize and Verbose TMailMng Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AlVerbose Initializes TMailMng and demonstrates toggling verbose output. ```protheus Local oServer := TMailMng():New( 0 ) conout( oServer:lVerbose ) // Vai exibir ".F." oServer:lVerbose := .T. conout( oServer:lVerbose ) // Vai exibir ".T." ``` -------------------------------- ### TButton with GoHome Action Source: https://tdn.totvs.com.br/display/tec/TWebEngine%3AGoHome This snippet shows how to create a TButton that navigates to the home page when clicked. It includes parameters for position, caption, parent dialog, action, and various other display and behavior options. ```Totvs `TButton():New( 172, 052, ``"GoHome"``, oDlg,{|| oTWebEngine:GoHome() },40,010,,,.F.,.T.,.F.,,.F.,,,.F. )` ``` -------------------------------- ### Exemplo completo de criação e consulta Source: https://tdn.totvs.com.br/display/tec/DBGoBottom Demonstra a criação de uma tabela, a chamada da função de inserção e a verificação de dados após a operação. ```AdvPL FUNCTION Example() Local cT1 := "T1" TCLink() DBCreate("T1", {{"FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}, ; {"FIELD_AGE", "C", 10, 0}, ; {"FIELD_NICK", "C", 10, 0}, ; {"FIELD_COL", "C", 10, 0}}, "TOPCONN") U_insert() DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .T.) (cT1)->(DBGoBottom()) IF ((cT1)->FIELD_AGE == "2222222 ") conout("Found!") ENDIF DBCloseArea() TCUnlink() RETURN ``` -------------------------------- ### Get Live Timer Status Source: https://tdn.totvs.com.br/display/tec/TTimer%3AlLiveAny This snippet retrieves the live status of a timer and displays it as an alert. Ensure the timer object and its 'lLiveAny' property are accessible. ```Protheus lLiveAny = oTimer:lLiveAny Alert(lLiveAny) ``` -------------------------------- ### Initialize TMailMng and access SSL property Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AnSrvSSL Demonstrates creating a new instance of TMailMng and retrieving the nSrvSSL property value. ```AdvPL Local oServer := TMailMng():New( 0, 3, 6 ) ``` ```AdvPL conout( oServer:nSrvSSL ) // Vai exibir "3" ``` -------------------------------- ### Get Calendar Event and Display Info Source: https://tdn.totvs.com.br/display/tec/TMobile%3AgetCalendarEvent Retrieves a calendar event using its ID and then displays its information. Ensure the oTMobile object and getCalendarEvent method are available in your environment. ```AdvPL oCalEv := oTMobile:getCalendarEvent(cCalId) varinfo("",oCalEv) ``` -------------------------------- ### Configure TMailMng SMTP Extension Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AlExtendSMTP Demonstrates how to instantiate TMailMng and toggle the lExtendSMTP property. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:lExtendSMTP ) // Vai exibir ".T." oServer:lExtendSMTP := .F. conout( oServer:lExtendSMTP ) // Vai exibir ".F." ``` -------------------------------- ### Configure SSL Source: https://tdn.totvs.com.br/display/tec/SSL3?showLanguage=pt_PT This snippet configures SSL settings. Set SSL3 to 1 to enable it. ```ini [SSLConfigure] SSL3 = 1 ``` -------------------------------- ### Start New Conversation - ADVPL Source: https://tdn.totvs.com.br/display/tec/Classe%2BtRedisClient Initiates a new chat conversation with a specified user. It includes checks to prevent users from conversing with themselves and logs the action. Use this before calling TcConversa. ```advpl Static Function NovaConversa(cNovoUsuario)    Local cMsg := ""    If(cUsuario == Nil .Or. Len(cUsuario) <= 0)       PRT_ERROR("Nao tem usuario Logado")       Return .F.    EndIf    If(cUsuario == cNovoUsuario)          cMsg := 'E "'+ cUsuario + '" disse: ' + CRLF + '- Voce nao deve conversar com voce mesmo "' + cUsuario + '"'          MessageBox(cMsg, "???", 48)          PRT_ERROR(cMsg)          Return .F.    EndIf    PRT_MSG(cUsuario + " iniciando com versa com: " + cNovoUsuario)    TcConversa(cUsuario, cNovoUsuario) Return .T. ``` -------------------------------- ### Initialize and Configure TWsdlManager Source: https://tdn.totvs.com.br/display/tec/TWsdlManager%3AlVerbose Instantiates the TWsdlManager object and enables verbose mode for debugging purposes. ```AdvPL Local oWsdl := TWsdlManager():New() ``` ```AdvPL oWsdl:lVerbose := .T. ``` -------------------------------- ### Get List of Items - ADVPL Source: https://tdn.totvs.com.br/display/tec/Classe%2BtRedisClient Retrieves a list of items from a specified source. It handles connection, command execution, sorting, and filtering. Use when you need to fetch and process data from a named list. ```advpl Static Function obtemLista(cNomeLista, aItens, cLog, cIgnora)    Local nX := 0    Local cCmd := Nil    Local xRetCmd := Nil    aItens := {}    If(connect() == .F.)       Return .F.    EndIf    cCmd := "SMEMBERS "+ cNomeLista    If .Not. execCmd(cCmd, @xRetCmd)       Return .F.    EndIf    //VarInfo("obtemLista", xRetCmd)    ASort(xRetCmd)    For nX := 1 to Len(xRetCmd)       If(cIgnora == Nil .Or. .Not. (cIgnora == xRetCmd[nX]))          AAdd(aItens, {.F., xRetCmd[nX]})          //PRT_MSG(cLog + "[" + cValToChar(nX) + "] = " + xRetCmd[nX])       EndIf    Next    //VarInfo("aItens", aItens) Return .T. ``` -------------------------------- ### Example TC_ALTER FAILED Log Analysis Source: https://tdn.totvs.com.br/display/tec/TC_ALTER%2BFAILED%2Bon%2Bfile...%2BTable%2BDATA%2Bor%2BSTRUCTURE%2Bshould%2Bbe%2BINVALID%2Bor%2BCORRUPTED This log snippet demonstrates a TC_ALTER FAILED error caused by a statistics object ('CTB_FILORI') being dependent on a column ('CTB_FILORI') that is being dropped. It shows the initial error from the SQL Server driver and the subsequent TC_ALTER FAILED message from the TOTVS DBAccess. ```log 04/01/2016 12:52:20 : [BEGINLOG] Error : 5074 (37000) (RC=-1) - [Microsoft][ODBC SQL Server Driver][SQL Server]The statistics 'CTB_FILORI' is dependent on column 'CTB_FILORI'. ( From tMSSQLConnectionAlterTable_1 ) Thread ID [6096] User [sigasp] IO [5800] Tables [0] MaxTables [1] Comment [] Status [] SP [ ] Traced [No] InTran [No] DBEnv [MSSQL/BASEP12TST] DBThread [(SPID 132)] Started [04/01/2016 12:50:17] LastIO [] IP [192.168.0.202:1245] RCV [62330] SND [184900] TCBuild [20141119] ALTER TABLE dbo.CTB010 DROP COLUMN CTB_FILORI [ENDLOG] 04/01/2016 12:52:20 : [BEGINLOG] TC_ALTER FAILED on file [CTB010]. Table DATA or STRUCTURE should be INVALID or CORRUPTED. ( From tDBServer::AlterFile ) Thread ID [6096] User [sigasp] IO [5800] Tables [0] MaxTables [1] Comment [] Status [] SP [ ] Traced [No] InTran [No] DBEnv [MSSQL/BASEP12TST] DBThread [(SPID 132)] Started [04/01/2016 12:50:17] LastIO [] IP [192.168.0.202:1245] RCV [62330] SND [184900] TCBuild [20141119] ``` -------------------------------- ### Configure TMailMng SMTP settings Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AcSMTPAddr Initializes the TMailMng object and demonstrates setting SMTP server address, user credentials, and connection establishment. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:cSMTPAddr ) // Vai exibir "" oServer:cSMTPAddr := "mail.totvs.com.br" conout( oServer:cSMTPAddr ) // Vai exibir "mail.totvs.com.br" oServer:cUser := "totver" oServer:cPass := "mypass" oServer:SMTPConnect() oServer:cSMTPAddr := "mail.google.com" conout( oServer:cSMTPAddr ) // Vai exibir "mail.totvs.com.br" ``` -------------------------------- ### Read JSON file with fromJsonFile Source: https://tdn.totvs.com.br/display/tec/fromJsonFile Demonstrates reading a JSON file from a specified path and handling the return value. ```TL++ # include tlpp-core.th function u_capturaJsonFile() local cPathAndFile := 'C:\tlppcore\fromjsonfile.txt' local oJsonObject := JSONObject():New() local xReturn := Nil xReturn := oJsonObject:fromJsonFile(cPathAndFile) if valType(xReturn) == "U" conout("Arquivo: "+cPathAndFile+" lido com sucesso") else conout("Erro: "+cValToChar(xReturn)+" na leitura do arquivo: "+cPathAndFile) endif freeObj(oJsonObject) return ``` -------------------------------- ### Create and Query TOPCONN Database Source: https://tdn.totvs.com.br/display/tec/DBGoTop Creates a 'TOPCONN' database with specified fields, inserts data using U_insert, and checks for a specific age value. Requires TCLink and TCUnlink for database connection management. ```advpl FUNCTION Example() Local cT1 := "T1" TCLink() DBCreate("T1", {{ "FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}, ; {"FIELD_AGE", "C", 10, 0}, ; {"FIELD_NICK", "C", 10, 0}, ; {"FIELD_COL", "C", 10, 0}}, "TOPCONN") U_insert() DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .T.) (cT1)->(DBGoTop()) IF ((cT1)->FIELD_AGE == "22 ") conout("Found!") ENDIF DBCloseArea() TCUnlink() RETURN ``` -------------------------------- ### Configure HTTP Server Settings Source: https://tdn.totvs.com.br/display/tec/Cache-Control?showLanguage=all This configuration block enables the HTTP server, sets the port to 80, specifies the HTML content path, and enforces no-store caching. Ensure the path D:\ERP\Html exists and is accessible. ```INI [HTTP] Enable=1 Port=80 Path=D:\ERP\Html **Cache-control=no-store** ``` -------------------------------- ### Define Feature Constants and Open Settings Source: https://tdn.totvs.com.br/display/tec/TMobile%3AOpenSettings Defines integer constants for device features and invokes the OpenSettings method with a specific feature parameter. ```AdvPL #define BLUETOOTH_FEATURE 1 #define NFC_FEATURE 2 #define WIFI_FEATURE 3 #define LOCATION_FEATURE 4 oMbl:OpenSettings(LOCATION_FEATURE) ``` -------------------------------- ### Configure SSL Client Certificate Source: https://tdn.totvs.com.br/display/tec/SecondCertificateClient Use this configuration block to specify the path to the client certificate file for SSL authentication. ```ini [SSLConfigure] SecondCertificateClient=C:\cert\ca-client.pem ``` -------------------------------- ### Create Note Input Field Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for capturing notes. The callback function updates the cGetNote variable. ```advpl cGetNote := Space( 256 ) oGetNote := TGet():New( 65, 5, { | u | If( PCount() == 0, cGetNote,; cGetNote := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F., .F.,; .F., .F.,, "cGetNote" ,,,, .F.,,, "Note:" , 2 ) ``` -------------------------------- ### Verificar arquitetura do servidor com isSrv64 Source: https://tdn.totvs.com.br/display/tec/IsSrv64?showLanguage=all Utilize esta função para identificar se o Application Server está rodando em uma arquitetura de 64 bits. ```AdvPL User Function teste() local lisSrv64 := isSrv64() if ( lisSrv64 ) conout( "Application Server is 64 bit" ) else conout( "Application Server not 64 bit" ) endif Return ``` -------------------------------- ### Create User List Dialog - ADVPL Source: https://tdn.totvs.com.br/display/tec/Classe%2BtRedisClient Defines and activates a dialog box for listing users. It initializes a TCBrowse object, populates it with user data using ListaUsers, and sets up a timer to refresh the list periodically. ```advpl Static Function TcUser()    Local oDlg2    DEFINE MSDIALOG oDlg2 FROM 0,0 TO 220,300 PIXEL TITLE 'Lista amigos de: ' + cUsuario + ' - Velho Novo ADVPL'    // Cria objeto de fonte que sera usado na Browse    Define Font oFont Name 'Courier New' Size 0, -12    // Cria Browse    oList2 := TCBrowse():New(01 ,01, 120, 100, ,{'CHAT', 'Usuario'},{30, 50},oDlg2,,,,,{||},,oFont,,,,,.F.,,.T.,,.F.,,, )    ListaUsers(@aList, /*cUsuario*/)    nMilissegundos := 2000 // Disparo sera de 2 em 2 segundos    oTimer := TTimer():New(nMilissegundos, {|| ListaUsers(@aList, /*cUsuario*/) }, oDlg2)    oTimer:Activate()    oList2:Refresh() // refresh da lista    ACTIVATE MSDIALOG oDlg2 CENTERED Return ``` -------------------------------- ### Create Name Input Field Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for capturing names. Sets up a callback function to update the cGetName variable. ```advpl cGetName := Space( 256 ) oGetName := TGet():New( 45, 5, { | u | If( PCount() == 0, cGetName,; cGetName := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F., .F.,; .F., .F.,, "cGetName" ,,,, .F.,,, "Name:" , 2 ) ``` -------------------------------- ### Insertion and Macro Options Source: https://tdn.totvs.com.br/display/tec/SetKey?showLanguage=all Details options for inserting content, links, tables, and macros. ```APIDOC ## Insertion and Macro Options ### Description Provides options for inserting various types of content, including files, links, markup, and dynamic macros. ### Insert Content - Files and images - Link - Markup - Horizontal rule - Task list - Date - Emoticon - Symbol ### Insert Macro - User mention - Jira Issue/Filter - Info - draw.io Diagram - Embed draw.io Diagram - draw.io Board Diagram - Status - Gallery - Table of Contents - Other macros ``` -------------------------------- ### Configure SSL Private Key Source: https://tdn.totvs.com.br/display/tec/SecondKeyServer?showLanguage=all Defines the path to the private key file within the SSL configuration section. ```ini [SSLConfigure] SecondKeyServer=C:\cert\priv-key.pem ``` -------------------------------- ### Salvar anexos de e-mail via POP3 Source: https://tdn.totvs.com.br/display/tec/TMailMessage%3ASaveAttach Exemplo de implementação para conectar a um servidor POP3, ler a última mensagem e salvar todos os anexos encontrados no diretório local. ```AdvPL user function saveAttach() Local oServer Local oMessage Local nAttach := 0, nI := 0 Local nMessages := 0 Local aAttInfo := {} Local cBaseName := "", cName := "" Local xRet oServer := TMailManager():New() writePProString( "Mail", "Protocol", "POP3", getsrvininame() ) oServer:SetUseSSL( .T. ) xRet := oServer:Init( "mail.totvs.com.br", "", "username", "password", 995, 0 ) if xRet <> 0 conout( "Could not initialize mail server: " + oServer:GetErrorString( xRet ) ) return endif xRet := oServer:POPConnect() if xRet <> 0 conout( "Could not connect on POP3 server: " + oServer:GetErrorString( xRet ) ) return endif oServer:GetNumMsgs( @nMessages ) conout( "Number of messages: " + cValToChar( nMessages ) ) oMessage := TMailMessage():New() oMessage:Clear() conout( "Receiving newest message" ) xRet := oMessage:Receive( oServer, nMessages ) if xRet <> 0 conout( "Could not get message " + cValToChar( nMessages ) + ": " + oServer:GetErrorString( xRet ) ) return endif cBaseName := GetSrvProfString( "RootPath", "" ) if Right( cBaseName, 1 ) <> '\' cBaseName += '\' endif cBaseName += "mail\pop3\" nAttach := oMessage:GetAttachCount() for nI := 1 to nAttach aAttInfo := oMessage:GetAttachInfo( nI ) varinfo( "", aAttInfo ) cName := cBaseName if aAttInfo[1] == "" cName += "message." + SubStr( aAttInfo[2], At( "/", aAttInfo[2] ) + 1, Len( aAttInfo[2] ) ) else cName += aAttInfo[1] endif conout( "Saving attachment " + cValToChar( nI ) + ": " + cName ) xRet := oMessage:SaveAttach( nI, cName ) if xRet == .F. conout( "Could not save attachment " + cName ) loop endif next nI xRet := oServer:POPDisconnect() if xRet <> 0 conout( "Could not disconnect from POP3 server: " + oServer:GetErrorString( xRet ) ) endif return ``` -------------------------------- ### Configure SSL Certificate Source: https://tdn.totvs.com.br/display/tec/SecondCertificateServer?showLanguage=all Specifies the path to the secondary SSL certificate file for server configuration. Ensure the file exists at the specified location. ```ini [SSLConfigure] SecondCertificateServer=C:\cert\ca-server.pem ``` -------------------------------- ### Utilização básica de TCDrivers Source: https://tdn.totvs.com.br/display/tec/TCDrivers Exemplo de como invocar a função TCDrivers dentro de uma user function. ```AdvPL user function teste() TCLink() varinfo( "driver", TCDrivers() ) TCUnlink() return 0 ``` -------------------------------- ### Configure SSL PassPhrase Source: https://tdn.totvs.com.br/display/tec/PassPhrase?showLanguage=pt_PT Defines the SSL configuration section and the required PassPhrase parameter. ```ini [SSLConfigure] PassPhrase=PIN ``` -------------------------------- ### Exemplo de uso das funções HSM Source: https://tdn.totvs.com.br/display/tec/HSMSlotList Demonstra a inicialização, listagem de slots e objetos, e finalização do HSM. ```AdvPL user function teste() Local aSlots := {} Local aObjs := {} Local nI := 0 Local nSlots := 0 Local cPass := "" cPass := "1234" if HSMInitialize() <= 0 conout( "HSM not initialized" ) return endif aSlots := HSMSlotList() nSlots := Len( aSlots ) varinfo( "slots", aSlots ) for nI := 1 to Len( aSlots ) if aSlots[nI][4] == .T. ASize( aObjs, 0 ) aObjs := HSMObjList( aSlots[nI][1], cPass ) varinfo( "aObjs", aObjs ) endif next nI if HSMFinalize() <> 1 conout( "HSM not finalized" ) endif return ``` -------------------------------- ### Create Email 2 Input Field and Type ComboBox Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for the second email address and a TComboBox for its type, utilizing the aTypes array. ```advpl cGetEmail2 := Space( 256 ) oGetEmail2 := TGet():New( 105, 5, { | u | If( PCount() == 0, cGetEmail2,; cGetEmail2 := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F., .F.,; , .F., .F.,, "cGetEmail2" ,,,, .F.,,, "E-mail 2:" , 2 ) cCmbEmail2:= aTypes[1] oCmbEmail2 := TComboBox():New( 105, 130, { |u| if( PCount() > 0,; cCmbEmail2 := u, cCmbEmail2 ) }, aTypes, 50, 10, oPanelScr,,,,,, .T.,,,,,; ,,,, "'cCmbEmail2'" , "Tipo:" , 2 ) ``` -------------------------------- ### Configurar evento bChange no oSlider Source: https://tdn.totvs.com.br/display/tec/TSlider%3AbChange Define um bloco de código para ser executado quando o evento bChange é disparado no componente oSlider. ```AdvPL oSlider:bChange := {|| Alert(``"bChange"``)} ``` -------------------------------- ### Enable SpinBox wrapping Source: https://tdn.totvs.com.br/display/tec/TSpinBox%3AsetWrap Configures the SpinBox to wrap its value when reaching the minimum or maximum limits. ```AdvPL oSpinBox:SetWrap( .T. ) ``` -------------------------------- ### Instantiate and Modify TMailMng Object Source: https://tdn.totvs.com.br/display/tec/TMailMng%3AcSMTPLocalhost Demonstrates how to instantiate the TMailMng object and modify its lAuthLogin property. The output shows the initial and modified values. ```AdvPL Local oServer := TMailMng():New( 0, 3, 3 ) conout( oServer:lAuthLogin ) // Vai exibir ".T." oServer:lAuthLogin := .F. conout( oServer:lAuthLogin ) // Vai exibir ".F." ``` -------------------------------- ### Configuração de Servidor HTTP Source: https://tdn.totvs.com.br/display/tec/RPCEnv%2B--%2B29365?showLanguage=all Exemplo de arquivo de configuração para o servidor HTTP, definindo porta, diretório raiz e timeout de RPC. ```ini [HTTP] Enable=1 Port=80 Path=D:\ERP\Html **RPCEnv=EnvTopP10** RPCTimeOut=40 ``` -------------------------------- ### List and Alignment Options Source: https://tdn.totvs.com.br/display/tec/SetKey?showLanguage=all Details options for creating lists and aligning text. ```APIDOC ## List and Alignment Options ### Description Options for creating bulleted, numbered, and task lists, as well as text alignment. ### List Options - Bullet list - Numbered list - Task list ### Alignment Options - Align left - Align center - Align right ``` -------------------------------- ### Create and Use Database Table Source: https://tdn.totvs.com.br/display/tec/DBCloseArea This function creates a new database table and then uses it. Ensure TCLink() is called before and TCUnlink() after. ```TDS FUNCTION Example() Local cT1 := "T1" TCLink() DBCreate( "T1", { {"FIELD_NAME", "C", 10, 0}, ; {"FIELD_TYPE", "C", 10, 0}, ; {"FIELD_AGE", "C", 10, 0}, ; {"FIELD_NICK", "C", 10, 0}, ; {"FIELD_COL", "C", 10, 0}}, "TOPCONN") DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .T.) // TODO DBCloseArea() TCUnlink() RETURN ``` -------------------------------- ### Configure SSL State Source: https://tdn.totvs.com.br/display/tec/State?showLanguage=all Sets the SSL configuration state. A value of 0 typically disables SSL. ```ini [SSLConfigure] STATE=0 ``` -------------------------------- ### Create Email 3 Input Field and Type ComboBox Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for the third email address and a TComboBox for its type, using the provided aTypes array. ```advpl cGetEmail3 := Space( 256 ) oGetEmail3 := TGet():New( 125, 5, { | u | If( PCount() == 0, cGetEmail3,; cGetEmail3 := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F., .F.,; , .F., .F.,, "cGetEmail3" ,,,, .F.,,, "E-mail 3:" , 2 ) cCmbEmail3:= aTypes[1] oCmbEmail3 := TComboBox():New( 125, 130, { |u| if( PCount() > 0,; cCmbEmail3 := u, cCmbEmail3 ) }, aTypes, 50, 10, oPanelScr,,,,,, .T.,,,,,; ,,,, "'cCmbEmail3'" , "Tipo:" , 2 ) ``` -------------------------------- ### Inserção de registros em tabela Source: https://tdn.totvs.com.br/display/tec/DBGoBottom Função para inserir múltiplos registros em uma tabela aberta via TOPCONN. ```AdvPL FUNCTION insert() Local cT1 := "T1" Local idx := 0 Local name := "" Local tp := "" Local age := "2" DBUseArea(.F., 'TOPCONN', cT1, (cT1), .F., .F.) WHILE (idx <= 5) name += "BA" tp += "T" age += "2" (cT1)->( DBAppend( .F. ) ) (cT1)->FIELD_NAME := name (cT1)->FIELD_TYPE := tp (cT1)->FIELD_AGE := age (cT1)->( DBCommit() ) idx++ ENDDO DBCloseArea() return ``` -------------------------------- ### Create Phone 2 Input Field and Type ComboBox Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for the second phone number and a TComboBox for its type, using the aTypes array for options. ```advpl cGetPhone2 := Space( 256 ) oGetPhone2 := TGet():New( 165, 5, { | u | If( PCount() == 0, cGetPhone2,; cGetPhone2 := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F., .F.,; , .F., .F.,, "cGetPhone2" ,,,, .F.,,, "Phone 2:" , 2 ) cCmbPhone2:= aTypes[1] oCmbPhone2 := TComboBox():New( 165, 130, { |u| if( PCount() > 0,; cCmbPhone2 := u, cCmbPhone2 ) }, aTypes, 50, 10, oPanelScr,,,,,, .T.,,,,,; ,,,, "'cCmbPhone2'" , "Tipo:" , 2 ) ``` -------------------------------- ### Configure SSL Verbose Logging Source: https://tdn.totvs.com.br/display/tec/Verbose?showLanguage=all Sets the SSL configuration to verbose mode for debugging purposes. ```ini [SSLConfigure] VERBOSE=1 ``` -------------------------------- ### Create Email 1 Input Field and Type ComboBox Source: https://tdn.totvs.com.br/display/tec/TMobile Initializes a TGet object for the first email address and a TComboBox for its type. The combo box uses the aTypes array for options. ```advpl cGetEmail1 := Space( 256 ) oGetEmail1 := TGet():New( 85, 5, { | u | If( PCount() == 0, cGetEmail1,; cGetEmail1 := u ) }, oPanelScr, 100, 10,,,,,, .F.,, .T.,, .F.,, .F.,; .F.,, .F., .F.,, "cGetEmail1" ,,,, .F.,,, "E-mail 1:" , 2 ) cCmbEmail1:= aTypes[1] oCmbEmail1 := TComboBox():New( 85, 130, { |u| if( PCount() > 0,; cCmbEmail1 := u, cCmbEmail1 ) }, aTypes, 50, 10, oPanelScr,,,,,, .T.,,,,,; ,,,, "'cCmbEmail1'" , "Tipo:" , 2 ) ``` -------------------------------- ### Definir Ação do Timer Source: https://tdn.totvs.com.br/display/tec/TTimer%3AbAction Define o bloco de código a ser executado pelo objeto Timer. ```AdvPL oTimer:bAction := {|| Alert("bAction")} ```