Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically changing RTF datawindow contents.

Status
Not open for further replies.

laiyewhon

Programmer
Mar 26, 2003
7
0
0
MY
Hi all,

I want to know if there's a way code an application (.PBD) to dynamically change the contents of a RTF datawindow in runtime and saving the changes?

I have an idea in which I can think of but unfortunately unable to implement to date: -

a) Declare a .pbl file into the .pbr during build, as a temporary library to store the dw. If this method works then I can use Infomaker to edit the dw but in the event that Infomaker is not awailable, how would I be able to save the datawindow from my application?

b) Can I use the libraryexport() function to export the dw, with the changes to the text, and then reimport it back into the .pbl referenced in my .pbr file? Would it retain the original SQL without the retrieval arguments passed in? Or would it save it with the SQL in the getsqlselect()?

Thanks,
Kelvin
 
If I understand you correctly you want to export a datawindow, make changes to the exported script and then re-import the changed script so that it will dynamically change your datawindw at runtime?

Well if so, this is what I have done in the past to accomplish this. First create a .pbl file with the datawindow you want to change at runtime inside it, not sure if this will work if you include this file in the .pbr file when building the app, but will definitely try that some time, but for now, just copy the .pbl file with the datawindow inside to the same directory as your executable file and DON’T include it in your library path of your application! If you do it will compile the .pbl file as a .pbd and we don’t want that, you want to keep it in a .pbl format. OK once you have done that in the code of your app place the following code:

String ls_datawindow_source

ls_datawindow_source = LibraryExport("dwlibrary.pbl", "d_datawindow_you_want_to_change", ExportDataWindow!)

This will return the full script of the datawindow as if you have exported it. Now just do a simple replace with the replace PB function which you can lookup in the PB help if you don’t know how. To see what the script looks like beforehand export the datawindow with the library painter and then determine what piece of script to look for and replace when you use the replace function. Once you have your modified script in another string value, for instance ls_new_script do the following:

int li_return
String ls_errors

li_return = dwcontrol.Create(ls_new_script, ls_errors)

dwcontrol is the name of the DataWindow control or DataStore in which PowerBuilder will create the new DataWindow object .
ls_new_script is the string whose value is the DataWindow source code that will be used to create the DataWindow object.
And ls_errors (optional) is the name of a string that will hold any error messages that occur. If you do not specify an error buffer, a message box will display the error messages. The Create function returns 1 if it succeeds and -1 if an error occurs.

If this all worked without errors all that is left to do is call the settransobject function and retrieve.

Hope this is what you wanted to know, but this is one of the ways I know of to modify a datawindow’s content at runtime, and it works.

Regards

Tentacle
 
Two other methods of changing the RTF. Both require a knowledge of how a rtf document is constructed. Some help may be at


These routines are only good for 32k size and less, otherwise they will need to be modified for larger files. We only use single page documents which work just fine.

1) simply load the RTF, copy each of the header, detail and footer contents, modify and paste the contents:
Code:
Boolean lb_hf
String  ls_rtf

If dw_tmp.Describe("DataWindow.RichText.HeaderFooter")="yes" Then
  lb_hf = True
Else
  lb_hf = False
End If

// Header
If lb_hf Then
  ls_rtf = rte_1.CopyRtf(False,Header!)
  // Modify contents
  rte_1.PasteRtf(ls_rtf,Header!)
End If
	
// Detail
ls_rtf = rte_1.CopyRtf(False,Detail!)
// Modify contents
rte_1.PasteRtf(ls_rtf,Detail!)

  // Footer
If lb_hf Then
  ls_rtf = rte_1.CopyRtf(False,Footer!)
  // Modify contents
  rte_1.PasteRtf(ls_rtf,Footer!)
End If
2) Save the rtf to a file, read the file, modify, resave and reload back into the rtf:
Code:
Integer li_file
String ls_rtfdata
String ls_fname

rte_1.SaveDocument(ls_fname, FileTypeRichText!)
If FileExists(ls_fname) Then
  li_file = FileOpen(ls_fname,StreamMode!,Read!,LockReadWrite!)
  FileRead(li_file, ls_rtfdata)
  FileClose(li_file)
  // Modify contents
  li_file = FileOpen(ls_fname,StreamMode!,Write!,LockReadWrite!,Replace!)
  FileWrite(li_file, ls_rtfdata)
  FileClose(li_file)
  rte_1.SelectTextAll()
  rte_1.Clear()
  rte_1.InsertDocument(ls_fname,TRUE, FileTypeRichText!)
End If
Paul Mele
DFAS-CL/TSTB
 
Thanks guys for your replys.

But assuming that I have a datawindow/template already ready but I want to allow the users to modify the datawindow/template and save it so that the next time users an retrieve it based on the changes they have made to the template.

Kelvin

 
We create a generic RTF document complete with text and data fields and save them into a RTF file. This is done during development using the application in a window we created with an RTF control just for making document.

During execution, we read the RTF document we saved and allow the user to make modifications after which we save and print the document. The saved document get put into our EDM system. You can just resave over the generic document making a new template for them.
Paul Mele
DFAS-CL/TSTB
 
Paul> Does it allow you to still maintain the sql and the columns selected in the datawindow by doing so?

Kelvin
 
The saved RTF file is separate from the sql and columns selected. It is just the text and data fields within the text that is saved to the file in RTF format readable with Windows Notepad.

You merely have design a datawindow with the sql leaving the header footer and detail bands blank. When you open the object/window with the rtf control, before you display the rtf control to the user you load the master or user template containing the text you want in the header footer and detail.

If I explained this correctly, you can see the text of the rtf and the actual sql and columns are completely separate. We designed an rtf control with an sql that contains all the possible columns we need for all of the master rtf letters we have.

Hope this helps? What you are doing can be done easily with a little design work up front. It took us quite a while to come up with a solution that works each and everytime, even for newly master letters the customer wants.
Paul Mele
DFAS-CL/TSTB
 
Hi Paul,

I have tried using rtf but I think it has some problems with the formatting of the rtf file and it was unable to retrieve the columns. I used office to create the template.
and used {table_name_column}.

Here is the script:

this.insertdocument(".\rtfdoc.rtf",true)

lds_letter = create datastore
lds_letter.dataobject = 'ds_rtfsqlselect'
lds_letter.settransobject(sqlca)
la_temp = lds_letter.retrieve(ls_fund,ls_holder,ld_amt)
la_temp = rte_1.DataSource(lds_letter)

Thanks.

btw this forum is much better than sybase's because I could not retrieve most of the articles there.
 
Unfortunately you cannot use Office to create or edit the file. The RTF that Office uses is not recognized by the control, nor or the fields used in the control. This is why we needed to create our own RTF editor. Also, we use notepad to edit the file manually. Its a pain since Sybase does not utilize the latest RTF spec.


Paul Mele
DFAS-CL/TSTB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top