How to use an RTE control as texteditor to update a databaseblob

Back Up

Author: Eric Aling
Accessed:

PB5 has a new control, the RichTextEdit control. You can use this RTE control to read/update database blob fields for text editing purposes. To do this, you need the PB SELECTBLOB statement to get the value from the database and the UPDATEBLOB statement to store it back to the database again.

First, get the data from a database blob column:

BLOB lbl_Descr
INTEGER li_W, li_H

SELECTBLOB blobcolumn FROM tableX INTO :lbl_descr WHERE ....;

/* To past this data into the RTE control do: */

rte_Main.selecttextall()
rte_Main.pastertf(string(lbl_Descr))

/* Now, because the RTE does not initially autowrap,we must force this. The AutoWrap property of the RTE control must be TRUE. */

li_W = rte_Main.width
li_H = rte_Main.height
rte_Main.setredraw(FALSE)
rte_Main.resize(1,1)
rte_Main.resize(li_W,li_H)
rte_Main.setredraw(TRUE)

/* Finally, set the Modified attribute to FALSE so that the RTE control is ready for use: */

rte_Main.Modified = FALSE

Storing RTE data to the database:

Now, to do the opposite, that is, storing the contents of the RTE control in the database column code the following. First check if it is modified, then check if it has a value because you can't use the UPDATEBLOB function with no data to update:


IF rte_Main.Modified THEN 
	lbl_Descr = blob(rte_Main.CopyRTF(FALSE)) 
	IF IsNull(lbl_Descr) OR trim(string(lbl_Descr)) = '' THEN 
		UPDATE tableX SET blobcolumn = NULL WHERE .... 
	ELSE 
		UPDATEBLOB tableX SET blobcolumn = :lbl_Descr WHERE .... 
	END IF 
END IF 

That's all there is. Note that with 16bit OS, you're limited to 59999 characters because of the conversion done by the String() function. On 32bit OS, you don't have this problem.

 

Back Up