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.
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