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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rich TextBox Control - problem with ControlSource

Status
Not open for further replies.

kazl

Programmer
Dec 9, 2002
68
GB
The following code creates a form with RTF controls and it would work except for one thing. On loading it displays "OLERTF" instead of the contents of the memo field.

Can anyone tell me where I've missed something out?
Thank you. Kaz.

Code:
SET CLASSLIB TO samples ADDITIVE
use rtf	&& test file = RTF.DBF with Source memo field

loMyForm = createobject("TryRTF1")
loMyForm.show()
read events

DEFINE CLASS TryRTF1 AS form
	Top = 0
	Left = 0
	DoCreate = .T.
	Caption = "Test RTF Form"
	Visible = .T.
	ctext = ""
	nStripSize = 0
	Name = "Form1"

	ADD OBJECT rtfcontrols1 AS rtfcontrols WITH ;
		Top = 50, ;
		Left = 30, ;
		Width = 313, ;
		Height = 32, ;
		SpecialEffect = 1, ;
		Name = "Rtfcontrols1", ;
		Cbofontname1.FontName = "MS Sans Serif", ;
		Cbofontname1.FontSize = 8, ;
		Cbofontname1.ToolTipText = "FontName", ;
		Cbofontname1.Name = "Cbofontname1", ;
		Cbofontsize1.FontName = "MS Sans Serif", ;
		Cbofontsize1.FontSize = 8, ;
		Cbofontsize1.Name = "Cbofontsize1", ;
		cmdBold.FontName = "Courier New", ;
		cmdBold.FontSize = 8, ;
		cmdBold.Name = "cmdBold", ;
		cmdItalic.FontName = "Courier New", ;
		cmdItalic.FontSize = 8, ;
		cmdItalic.Name = "cmdItalic", ;
		cmdColor.FontName = "Courier New", ;
		cmdColor.FontSize = 8, ;
		cmdColor.Name = "cmdColor"

	ADD OBJECT olertf AS olecontrol WITH ;
		Top = 90, ;
		Left = 12, ;
		Height = 97, ;
		Width = 349, ;
		OLEClass = "RICHTEXT.RichtextCtrl", ;
		ControlSource = "Thisform.cText", ;
		Name = "oleRTF"

	PROCEDURE Destroy
		REPLACE rtf.Source WITH THISFORM.oleRTF.TextRTF
	ENDPROC

	PROCEDURE Init
		IF TYPE("THIS.oleRTF") # "O" OR ISNULL(THIS.oleRTF)
			RETURN .F.
		ENDIF
		THIS.rtfControls1.cboFontName1.Value = THIS.oleRTF.Font.Name
		THIS.rtfControls1.cboFontSize1.FillList(THIS.oleRTF.Font.Name)
		THIS.rtfControls1.cboFontSize1.Value = ALLTRIM(STR(THIS.oleRTF.Font.Size))
	ENDPROC

	PROCEDURE Load
		THIS.cText = rtf.source
	ENDPROC

	PROCEDURE Activate
	ENDPROC

	PROCEDURE rtfcontrols1.Cbofontname1.InteractiveChange
		THIS.Parent.cbofontsize1.FillList(THIS.Value)
		THISFORM.oleRTF.SelFontName = THIS.Value
	ENDPROC

	PROCEDURE rtfcontrols1.Cbofontsize1.InteractiveChange
		THISFORM.oleRTF.SelFontSize = VAL(THIS.Value)
	ENDPROC

	PROCEDURE rtfcontrols1.cmdBold.Click
		THISFORM.oleRTF.SelBold = !THISFORM.oleRTF.SelBold
	ENDPROC

	PROCEDURE rtfcontrols1.cmdItalic.Click
		THISFORM.oleRTF.SelItalic = !THISFORM.oleRTF.SelItalic
	ENDPROC

	PROCEDURE rtfcontrols1.cmdColor.Click
		THISFORM.oleRTF.SelColor = GETCOLOR()
	ENDPROC

	ADD OBJECT cmdok AS CommandButton WITH ;
		Top = 204, ;
		Left = 300, ;
		Height = 30, ;
		Width = 60, ;
		Caption = 'OK', ;
		Visible = .T., ;
		Name = "CMDOK"
	
	PROCEDURE CmdOK.Click
		Clear Events
	ENDPROC

	ADD OBJECT shape1 AS shape WITH ;
		Top = 6, ;
		Left = 12, ;
		Height = 37, ;
		Width = 349, ;
		SpecialEffect = 0, ;
		Name = "Shape1"

	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		FontName = "Comic Sans MS", ;
		FontSize = 8, ;
		Caption = "Use the formatting options to change the appearance of the text.", ;
		Height = 17, ;
		Left = 24, ;
		Top = 16, ;
		Width = 332, ;
		Name = "Label1"

ENDDEFINE
 
ControlSource = "Thisform.cText

Hard to determine, but should this be your field name? Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
kazl

One of the quirks of this control is that you have to route the TABLENAME.memofield to be .ControlSource through a form property .cText as you have done.

I use a similar setup excepting that the value is not assigned in the .Load() event, but in the .Click() event of a commandbutton, which you might care to try.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
kazl

Try the following which works:-

Create a new form and add an RTF control

In the .Load() event put :-

CREATE CURSOR TEMP (memofield M)
APPEND BLAN
APPE MEMO TEMP.memofield from C:\temp\anyfile.rtf
THIS.cText = ALLTRIM(TEMP.memofield)

In the RTF control assign the Controlsource with

.ControlSource = THISFORM.cText

If you attempt to assign it in code, it will fail, and assigning it in the .Load() event will fail anyway as the object does not exist.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Thank you for your suggestions. I am running this in code rather than a form to see if I can give it to someone to fit it into a system written "the old fashioned way".

I installed the whole MSDN Library to find the answer in "Backgrounders". Add a property...

memo_name = "rtf.source"

PROCEDURE LostFocus
cMemo = this.memo_name
REPLACE &cMemo with THISFORM.oleRTF.TextRTF
endproc

PROCEDURE GotFocus
cMemo = this.memo_name
THISFORM.oleRTF.TextRTF = &cMemo
ENDPROC

Wonderful! I can carry on believing everything is possible.

Cheers. Kaz.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top