PDFViewer控件未实例化报错问题求助
问题:在无PDF预览的页面编辑时触发PDF控件实例化错误
在未包含PDF预览控件的「Illegal announcement form」页面执行编辑操作时,系统抛出错误提示:
The control add-in on control PDFViewer on page PDF Viewer has not been instantiated.
PDF预览控件通过页面扩展IllegalMonitoringPDFViewer添加至「Illegal Monitoring」页面的Factbox区域,仅配置了显示逻辑与触发器;PDF预览Factbox页面(PDFV PDF Viewer Factbox)通过usercontrol引用PDFViewer控件,相关代码如下:
页面扩展代码(IllegalMonitoringPDFViewer)
pageextension 80003 IllegalMonitoringPDFViewer extends " Illegal Monitoring " { layout { addfirst(factboxes) { part(PDFViewerMatrix; "PDFV PDF Viewer Factbox") { ApplicationArea = All; Visible = VisiblePDF; } } } var VisiblePDF: Boolean; trigger OnAfterGetRecord() var DocumentAttachment: Record "Document Attachment"; RecId: Integer; RecRef: RecordRef; begin VisiblePDF := false; RecRef.Open(Database::"illegal trade "); RecId := RecRef.Number(); DocumentAttachment.Reset(); DocumentAttachment.SetFilter("Table ID", Format(RecId)); DocumentAttachment.SetFilter("No.", Rec."No."); if DocumentAttachment.FindLast() then VisiblePDF := true else VisiblePDF := false; end; trigger OnAfterGetCurrRecord() var DocumentAttachment: Record "Document Attachment"; RecId: Integer; RecRef: RecordRef; begin VisiblePDF := false; RecRef.Open(Database::"illegal trade "); RecId := RecRef.Number(); DocumentAttachment.Reset(); DocumentAttachment.SetFilter("Table ID", Format(RecId)); DocumentAttachment.SetFilter("No.", Rec."No."); if DocumentAttachment.FindLast() then begin VisiblePDF := true; CurrPage.PDFViewerMatrix.Page.setrecord(DocumentAttachment); end else VisiblePDF := false; end; }
PDF预览Factbox页面代码(PDFV PDF Viewer Factbox)
page 80001 "PDFV PDF Viewer Factbox" { Caption = 'PDF Viewer'; PageType = CardPart; SourceTable = "Document Attachment"; DeleteAllowed = false; InsertAllowed = false; LinksAllowed = false; layout { area(content) { group(General) { ShowCaption = false; usercontrol(PDFViewer; "PDFV PDF Viewer") { ApplicationArea = All; trigger ControlAddinReady() begin SetPDFDocument(Rec); end; } } } } procedure setrecord(var DocumentAtt: Record "Document Attachment") begin SetPDFDocument(DocumentAtt); CurrPage.Update(false); end; local procedure SetPDFDocument(var DocumentAttachment: Record "Document Attachment") var PDFAsTxt: Text; begin CurrPage.PDFViewer.LoadPDF(PDFAsTxt, true); end; }
报错页面代码(Illegal announcement form)
page 50016 "Illegal announcement form" { Caption = 'Announcement form'; PageType = Card; SourceTable = "illegal trade "; RefreshOnActivate = false; layout {} }
无论在该页面编辑任何内容,都会触发上述错误,以下是解决思路:
解决思路
- 检查页面扩展的作用范围:确认页面扩展
IllegalMonitoringPDFViewer的目标页面名称是否准确,避免因名称空格或系统内页面名称不一致,导致扩展被错误应用到「Illegal announcement form」页面。 - 增加控件就绪判断:在
PDFV PDF Viewer Factbox的SetPDFDocument方法中,调用LoadPDF前先判断控件是否就绪,比如通过CurrPage.PDFViewer.Available属性检查,防止在控件未实例化时执行方法。 - 排查数据源联动事件:两个页面共用
illegal trade表,编辑操作可能触发了该表的全局事件订阅,进而调用了PDF控件相关逻辑。检查是否存在针对该表的事件触发器,在编辑时触发了PDF控件的初始化代码。 - 优化Factbox可见性控制:在页面扩展的
OnAfterGetCurrRecord触发器中,仅当VisiblePDF为true时才调用setrecord方法,避免在Factbox不可见时触发控件初始化逻辑。 - 调整控件加载时机:修改
ControlAddinReady的触发逻辑,确保仅当Factbox处于激活状态时才执行SetPDFDocument,或者在setrecord方法中先等待控件就绪再加载PDF。
内容的提问来源于stack exchange,提问作者Maksio
相关产品推荐
相关产品推荐

