1. Glenn Scamman
  2. PowerBuilder
  3. Wednesday, 22 September 2021 11:22 PM UTC

I'm using PB2019 R3 Build 2703.

The TX Text Control ActiveX 28.0 control appears to have an issue saving document margin info.  You can set the margins on the control in powerscript, and they will appear properly while the document is open, but when you save the .rtf document, the margins are always just "1" in the resulting file.  Interestingly enough, if you save with a .doc extension (older Word format), the margins are saved fine.  I tried saving as HTML, and it loses the margin information too.  Using the margin arrows in the RTE control ruler-bar also works visually, but doesn't seem to set the margin values for saving. 

I searched around, and many people have also had issues with the RTE controls, but I didn't find any solutions for how to fix the margins issue.

Since the problem only manifests itself in the saved RTF documents, I decided to capture the margin properties right before saving, and then open and write the proper margin values into the just-saved file.  So far, this has worked, so I thought I'd share it for others experiencing this problem.  If there is a true solution to this issue, rather than a workaround, please let me know.

 

Step 1 - BEFORE the call to rte_1.SaveDocument( ls_filename ), get the margin values

Long ll_B, ll_T, ll_L, ll_R
String ls_FileType, ls_Temp

//Get the real margins (in 1/1000ths of an inch)
//Found I must get these BEFORE the save, because the control and the file both switch to '1' during the save.
ll_B = rte_1.BottomMargin
ll_T = rte_1.TopMargin
ll_L = rte_1.LeftMargin
ll_R = rte_1.RightMargin

 

Step 2 - I wrote a function to be called right AFTER the rte_1.SaveDocument( ls_filename ) call. 

I named the function of_FixFileMargins. Pass the file name with path, and the margin values to this function.

/******************************************************************************
Desc: Fix an apparent RTE control bug, which, when saving RTE control contents to a .rtf file, it ignores the
margins that have been set, and saves them as '1' no matter what. I'm opening and fixing the file.
Prog: Glenn Scamman
Date: 21-Sep-21
Arguments: String Value as_filename (The full path of the file just saved by the SaveDocument command)
Long Value al_L (The left margin value, in 1/1000ths of an inch)
Long Value al_T (The top margin value, in 1/1000ths of an inch)
Long Value al_R (The right margin value, in 1/1000ths of an inch)
Long Value al_B (The bottom margin value, in 1/1000ths of an inch)
Mods:
--------- --- -----------------------------------------------------------------
******************************************************************************/
Boolean lb_Changed
Integer li_File
Long ll_Rtn, ll_Pos, ll_twips
String ls_FileString, ls_NewMargin
n_cst_String lnv_String

lb_Changed = FALSE

//Open the just-saved file, and alter the margin entries. Must convert 1/1000ths to twips.
li_File = FileOpen( as_filename, TextMode!)
if li_File >= 0 then
//Fileread never worked until I didn't supply the optional value, but then I can't write to the file.
//Opening a file with Replace! mode, wipes out the file even if you aren't ready to.
//I'll try reading in one pass, then if it needs adjustment, writing in a second pass.
ll_Rtn = FileReadEx( li_File, ls_FileString )
FileClose( li_File )
if ll_Rtn < 0 then
RETURN -1
end if
end if

//Search the string for the margin commands to replace.
ll_Pos = Pos( ls_FileString, "\margl1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_L * 1.440
ls_NewMargin = "\margl" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margl1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margt1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_T * 1.440
ls_NewMargin = "\margt" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margt1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margr1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_R * 1.440
ls_NewMargin = "\margr" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margr1\", ls_NewMargin, TRUE )
end if
ll_Pos = Pos( ls_FileString, "\margb1\" )
if ll_Pos > 0 then
lb_Changed = TRUE
ll_twips = al_B * 1.440
ls_NewMargin = "\margb" + String(ll_twips) + "\"
ls_FileString = lnv_string.of_GlobalReplace( ls_FileString, "\margb1\", ls_NewMargin, TRUE )
end if

//If margins are off (which they always are), then re-write the file with the proper margins.
if lb_Changed then
li_File = FileOpen( as_filename, TextMode!, Write!, LockReadWrite!, Replace!)
if li_File >= 0 then
//Write the amended string back to the file
ll_Rtn = FileWriteEx( li_File, ls_FileString )
ll_Rtn = FileClose( li_File )
end if
else
RETURN 0
end if

RETURN 1

 

I apologize for not knowing how to format very will in this website. All the indenting was lost when pasting the code.

Regards...


Responses (3)
  1. Likes
  2. Latest
  3. Oldest
Loading...

Find Questions by Tag

.EXE .NET 6.0 .NET Assembly .NET Core 3.1 .NET Core Framework .NET DataStore .NET Std Framework 32-bit 64-bit ADO.NET AEM AI Algorithm Amazon AWS Android Apache API APK App Store App Store (Apple) Appeon Workspace Appeon Xcelerator Plug-in Architecture Array ASE Asynchronous Methods Authentication AutoBuild AutoCompiler Automated Testing Automation AutoScript Azure Barcode Base64 Batch BigData BLOB Branch & Merge Browser Bug Build Button C# C# Class Importer C# Editor C# Model generator Calendar Camera Certificate Chrome Citrix Class Client Client/Server Cloud Cluster Collection COM Command Line Compiler Compression Computed Field Configuration Controls Cookies Cordova Crash Cross-Platform Crosstab CSharpAssembly CSharpObject CSS CSV Cursor Data Database Database Driver Database Painter Database Profile Database Provider DataObject DataSource DataStore DataStore (C#) DataStore (PS) DataType DataWindow DATE DATETIME DB2 Debug Debugger Debugging Deployment Design DLL DO-WHILE Dockable Docker Documentation DOUBLE Download DragDrop Edge Edit Style Editor Elevate Conference Email Embedded SQL Emulator Encoding Encryption Enhancement Request Entity Entity Framework ERP Error Event Event Handler Event Handling Excel Exception Export Expression External Functions F# Field File File Access Filter Firefox Firewall Font FOR-NEXT Foreground Format Function Garbage Collection GeoLocation Git Graph HANA Hash Header HTML/5 HTTP/S HTTPClient Icon IDE Identity IIS IMAPI Import InfoMaker Inheritance Installation Integer IntelliSense Interface Internet Internet Explorer iOS IPA iPad iPhone IWA J# Java JavaScript JBoss JDBC JOIN JSON JSONGenerator JSONParser Kestrel Label Lambda Large File LDAP Library License LINQ Linux OS Load Balancing Localization Localized PBVM Log In Log Out Logging LONG LONGLONG macOS MAPI Maps MDI Memory Memory Leak Menu Merge MessageBox Messagging Method Migration MIME TYPE Mobile Model ModelStore ModelStore (C#) MSOLEDBSQL Multi Threading MVC MySQL n-Tier Namespace NativePDF NVO OAuth ODATA ODBC Office Offline OLE OLEDB Online Open Source OpenAPI OpenSSL Oracle OrcaScript Other Outlook Output Package Parameter Patch PayPal PB Classic PB Native PB.NET PBC PBD PBDOM PBG PBJVM PBL PBNI PBORCA PBVM PBX PDF Performance Permission PFC Picture Pipeline Play Store (Google) Plugin Popup Port POST PostgreSQL PowerBuilder PowerBuilder (Appeon) PowerBuilder (SAP) PowerBuilder Compiler PowerBuilder Runtime PowerClient PowerScript (PS) PowerScript IDE PowerScript Migrator PowerServer PowerServer Mobile PowerServer Toolkit PowerServer Web PowerServerLabel Print Properties Proxy Publish PULL PUSH Query Regression Release Renew Resize Response REST Retrieve RibbonBar RibbonBar Builder Rich Text Roadmap RPC Runtime Packager SaaS Scaffolding Script SDI SDK Security Server Service Session Single Sign-on Size SMTP SMTPClient SnapDevelop SOAP Sort Source Code Speech Recognition SQL SQL Anywhere SQL Server SqlBuilder SqlExecutor SQLite SqlModelMapper Storage Stored Procedure Subscription SVN Swagger Syntax TabbedBar TabbedView Tablet TabPage Target TE Control Testing Text TFS Theme TIME Timer TLS/SSL Tomcat TortoiseGit TortoiseSVN Transaction Transparency Trial Trigger TRY-CATCH TX Control Type UI ULONG UltraLite Uninstall Unit Test Unit Testing UNIX OS Update Upgrade Upload URL User Center User Object UWP Validation VARCHAR Variable Versioning Visual Studio Visual Studio Code VM Voice Warning WCF Web API Web Extensions Web Service WebBrowser WebForms WebLogic WebSphere WildFly WinAPI Window Windows OS WinForms Wizard Workgroup Workspace WPF XCODE XHTML XML Zoom

Helpful?

If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.