advpl-advanced
Skill1 starsChanged 6 months agoMITView on GitHub
Tópicos avançados ADVPL — transações com Begin Transaction, relatórios TReport, FWTemporaryTable, manipulação de arquivos texto, MsNewGetDados, TCBrowse, OOP em ADVPL clássico, arredondamento NoRound, técnicas de programação eficiente. Use quando contexto sair do escopo básico de cadastros/MVC.
In this repository29 other files it gives its agents.
- advpl-code-reviewSkill
- advpl-dicionario-sxSkill
- advpl-embedded-sqlSkill
- advpl-encodingSkill
- advpl-fundamentalsSkill
- advpl-jobs-rpcSkill
- advpl-matxfisSkill
- advpl-mvc-avancadoSkill
- advpl-mvcSkill
- advpl-pontos-entradaSkill
- advpl-tlppSkill
- advpl-webserviceSkill
- advpl-webSkill
- archSkill
- calleesSkill
- callersSkill
- doctorSkill
- findSkill
- grepSkill
- helpSkill
- ingestSkill
- initSkill
- lintSkill
- paramSkill
- plugadvpl-index-usageSkill
- reindexSkill
- setupSkill
- statusSkill
- tablesSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 71
Use Família 2 para layouts SEFAZ, SPED, EDI.
- Very specific: line 106
Use For Each em vez de For/Next com índice quando possível.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
advpl-advanced — Tópicos avançados ADVPL
ADVPL avançado cobre o que vai além do CRUD MVC básico: transações ACID, relatórios estruturados (TReport), manipulação de arquivos em massa, captura de informações multi-linha (grids dinâmicas), legacy Modelo2/Modelo3, e técnicas de programação eficiente.
Quando usar
- Usuário pede "relatório", "TReport", "impressão", "PDF".
- Necessidade de
Begin Transaction/BeginTran(gravações atômicas multi-tabela). - Manipulação de arquivos texto (
.csv,.txt, layouts EDI/SEFAZ) comFCreate/FOpen/FRead/FWriteouFT_FUse/FT_FReadLn. - Telas com grids dinâmicas (
MsNewGetDados,TCBrowse) fora do contexto MVC. - Performance de loops, arredondamento financeiro (
NoRound), I/O bulk. - Migrações de código
Modelo1/Modelo2/Modelo3/AxCadastro(legacy) → MVC moderno.
Transações — Begin Transaction × BeginTran
Begin Transaction
RecLock("SC5", .T.)
SC5->C5_NUM := cNumPed
MsUnlock()
RecLock("SC6", .T.)
SC6->C6_NUM := cNumPed
MsUnlock()
If lErro
DisarmTransaction()
Break
EndIf
End TransactionBegin Transaction é multi-tabela ACID. BeginTran/EndTran é forma alternativa. Nunca abra UI dentro de transação (trava o banco).
TReport — relatórios estruturados
oReport := TReport():New("XYZREL", "Relatorio XYZ", "XYZREL", {|oReport| ReportPrint(oReport)}, "Relatorio de demonstracao")
oSecao := TRSection():New(oReport, "Itens", {"SA1"})
TRCell():New(oSecao, "A1_COD", "SA1")
TRCell():New(oSecao, "A1_NOME", "SA1")
oReport:PrintDialog()TReport substitui legacy SetPrint/RptStatus. Sai em PDF/Excel/CSV nativo.
FWTemporaryTable — tabelas temporárias
Para queries complexas que precisam de tabela intermediária sem poluir SQL nativo:
oTmp := FWTemporaryTable():New("TMP")
oTmp:SetFields({{"COD", "C", 6, 0}, {"VLR", "N", 14, 2}})
oTmp:AddIndex("01", {"COD"})
oTmp:Create()
// usa "TMP" como alias normal
oTmp:Delete()Manipulação de arquivos texto
Duas famílias:
- Família 1:
FCreate/FOpen/FRead/FWrite/FClose— manipulação binária/baixo-nível. - Família 2:
FT_FUse/FT_FReadLn/FT_FGoTop/FT_FEof— leitura linha-a-linha eficiente (até GB).
Use Família 2 para layouts SEFAZ, SPED, EDI. Use Família 1 para arquivos binários ou pequenos.
MsNewGetDados — grid dinâmica fora de MVC
aHeader := {{"Codigo", "COD", "@!", 6, 0, "", "", "C", "", ""}, ...}
aCols := {{"", "", .F.}} // linha vazia inicial
oGrid := MsNewGetDados():New(0, 0, 200, 400, GD_INSERT+GD_UPDATE+GD_DELETE, ;
"AllwaysTrue", "AllwaysTrue", "", , 999, , , , oDlg, aHeader, aCols)Padrão para dialogs ad-hoc onde MVC seria over-engineering.
OOP em ADVPL clássico — Class … Method
Class TMyClass
Data cAtributo
Method New() Constructor
Method DoSomething()
EndClass
Method New() Class TMyClass
::cAtributo := ""
Return Self
Method DoSomething() Class TMyClass
ConOut("hello")
ReturnEm TLPP, sintaxe é mais moderna (ver skill advpl-tlpp).
Boas práticas de eficiência
- Use
For Eachem vez deFor/Nextcom índice quando possível. - Evite
+em loop para construir strings — use array +Array2String. NoRound(nValor, nCasas)para arredondamento financeiro determinístico.- Capitulação de palavras-chave:
Local,If,EndIfem PascalCase (convenção). - Evite
Publicglobal — useStaticno fonte ouLocalna função.
Anti-padrões
AxCadastro/Modelo2/Modelo3em código novo →MOD-004(deprecado).MsgInfo/Alertem JOB → bloqueia execução.Begin Transactioncom UI dentro → deadlock garantido.- Concatenar string em loop com
+em vez deArray2String. - Não tratar erros de
FOpen/FRead(retornam-1).
Referência profunda
Para detalhes completos (~2.3k linhas), consulte reference.md ao lado deste arquivo:
- Apostila ADVPL II completa (TOTVS) com programação de atualização, browses, transações.
- Catálogo de relatórios TReport com TRSection, TRCell, TRPosition, fórmulas, agrupamentos.
- Família completa de manipulação de arquivos (Famílias 1 e 2, FwTemporary*, FWFileReader/Writer).
- Componentes de interface visual (TDialog, TGet, TButton, TFolder, TPanel, TBitmap, TScrollBox).
- Boas práticas: arredondamento, identação, capitulação, técnicas de programação eficiente.
Comandos plugadvpl relacionados
/plugadvpl:find function TReport— relatórios indexados./plugadvpl:find function Begin Transaction— transações no projeto./plugadvpl:lint <arq>— detecta MOD-004 (rotina legacy).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

