- Glenn Scamman
- PowerBuilder
- 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...
Find Questions by Tag
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.