Dear Sergey,
Pervious function have some problem and I can not use from it.
I found another way that it is COPY & PASTE. I you run below code, you can see that when I click on three command button respectively, all things is good.
But if I do this function with AUTOMATIC ACTION command button it is wrong.
Can you help me for correcting this code?
Thank you very much.
PUBLIC oForm
oForm = CREATEOBJECT("MyRtf")
oForm.show
RETURN
DEFINE CLASS myrtf AS form
Top = 0
Left = 0
Height = 439
Width = 621
ShowWindow = 1
DoCreate = .T.
ShowTips = .T.
AutoCenter = .F.
BorderStyle = 3
Caption = "Edit Answer"
ControlBox = .F.
MaxButton = .F.
MinButton = .F.
MinWidth = 580
WindowType = 1
HelpContextID = 154
y_counter = 1
Name = "rad_answer"
ADD OBJECT shape1 AS shape WITH ;
Top = 223, ;
Left = 91, ;
Height = 157, ;
Width = 106, ;
BackStyle = 0, ;
SpecialEffect = 0, ;
Name = "Shape1"
ADD OBJECT olertf1 AS olecontrol WITH ;
Top = 4, ;
Left = 57, ;
Height = 52, ;
Width = 557, ;
TabIndex = 4, ;
OLEClass="RICHTEXT.RichtextCtrl.1",;
ControlSource = "", ;
Name = "oleRTF1"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 408, ;
Left = 268, ;
Height = 27, ;
Width = 84, ;
Caption = "EXIT", ;
TabIndex = 7, ;
Name = "Command1"
ADD OBJECT olertf2 AS olecontrol WITH ;
Top = 57, ;
Left = 57, ;
Height = 153, ;
Width = 557, ;
TabIndex = 5, ;
OLEClass="RICHTEXT.RichtextCtrl.1",;
ControlSource = "", ;
Name = "oleRTF2"
ADD OBJECT command3 AS commandbutton WITH ;
Top = 280, ;
Left = 96, ;
Height = 48, ;
Width = 96, ;
WordWrap = .T., ;
Caption = "copy rtf string from oleRTF1", ;
TabIndex = 2, ;
Name = "Command3"
ADD OBJECT command4 AS commandbutton WITH ;
Top = 327, ;
Left = 96, ;
Height = 48, ;
Width = 96, ;
WordWrap = .T., ;
Caption = "Paste rtf string to oleRTF2", ;
TabIndex = 3, ;
Name = "Command4"
ADD OBJECT command5 AS commandbutton WITH ;
Top = 240, ;
Left = 348, ;
Height = 27, ;
Width = 107, ;
Caption = "Automatic Action", ;
TabIndex = 6, ;
Name = "Command5"
ADD OBJECT command2 AS commandbutton WITH ;
Top = 228, ;
Left = 96, ;
Height = 48, ;
Width = 96, ;
WordWrap = .T., ;
Caption = "Store rtf string in oleRTF1", ;
TabIndex = 1, ;
Name = "Command2"
ADD OBJECT label1 AS label WITH ;
Caption = "oleRTF1", ;
Height = 17, ;
Left = 4, ;
Top = 16, ;
Width = 50, ;
TabIndex = 8, ;
Name = "Label1"
ADD OBJECT label2 AS label WITH ;
Caption = "oleRTF2", ;
Height = 17, ;
Left = 4, ;
Top = 76, ;
Width = 50, ;
TabIndex = 9, ;
Name = "Label2"
PROCEDURE Init
PUBLIC cRtfText1, cRtfText2, cRtfText3, cRtfText4, cRtfText5
cRtfText1 = "{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Arial;}" + ;
"{\f1\fswiss\fcharset178{\*\fname Arial;}Arial (Arabic);}}\viewkind4\uc1\pard\rtlpar\lang1033\f0\fs20 This is line 1 for rtf copy and paste test.\lang1065\f1\rtlch\par}"
cRtfText2 = "{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Arial;}" + ;
"{\f1\fswiss\fcharset178{\*\fname Arial;}Arial (Arabic);}}{\colortbl ;\red255\green0\blue0;}" + ;
"\viewkind4\uc1\pard\rtlpar\cf1\lang1033\f0\fs20 This is line 2 for rtf copy and paste test.\lang1065\f1\rtlch\par}"
cRtfText3 = "{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Arial;}" + ;
"{\f1\fswiss\fcharset178{\*\fname Arial;}Arial (Arabic);}}{\colortbl ;\red0\green0\blue0;}" + ;
"\viewkind4\uc1\pard\rtlpar\cf1\lang1033\b\f0\fs20 This is line 3 for rtf copy and paste test.\lang1065\f1\rtlch\par}"
cRtfText4 = "{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Arial;}" + ;
"{\f1\fswiss\fcharset178{\*\fname Arial;}Arial (Arabic);}}{\colortbl ;\red0\green0\blue0;}" + ;
"\viewkind4\uc1\pard\rtlpar\cf1\lang1033\i\f0\fs28 This is line 4 for rtf copy and paste test.\lang1065\f1\rtlch\par}"
cRtfText5 = "{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Arial;}" + ;
"{\f1\fswiss\fcharset178{\*\fname Arial;}Arial (Arabic);}}{\colortbl ;\red0\green0\blue0;}" + ;
"\viewkind4\uc1\pard\rtlpar\cf1\lang1033\ul\f0\fs28 This is line 5 for rtf copy and paste test.\lang1065\f1\rtlch\par}"
IF TYPE("THIS.oleRTF1") # "O" OR ISNULL(THIS.oleRTF1)
RETURN .F.
ENDIF
thisform.oleRTF1.TextRTF = ""
thisform.oleRTF2.TextRTF = ""
ENDPROC
PROCEDURE command1.Click
thisform.Release
ENDPROC
PROCEDURE command3.Click
#DEFINE KEYEVENTF_KEYUP 0x02
#DEFINE VK_CONTROL 0x11
DECLARE INTEGER keybd_event IN Win32API ;
INTEGER, INTEGER, INTEGER, INTEGER
Thisform.oleRTF1.Setfocus()
keybd_event(VK_CONTROL, 0, 0, 0)
keybd_event(0x41, 0, 0, 0)
keybd_event(0x43, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
DOEVENTS FORCE
CLEAR DLLS "keybd_event"
ENDPROC
PROCEDURE command4.Click
#DEFINE KEYEVENTF_KEYUP 0x02
#DEFINE VK_CONTROL 0x11
DECLARE INTEGER keybd_event IN Win32API ;
INTEGER, INTEGER, INTEGER, INTEGER
Thisform.oleRTF2.Setfocus()
keybd_event(VK_CONTROL, 0, 0, 0)
keybd_event(0x23, 0, 0, 0)
keybd_event(0x56, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
CLEAR DLLS "keybd_event"
ENDPROC
PROCEDURE command5.Click
thisform.oleRTF1.TextRTF = ""
thisform.oleRTF2.TextRTF = ""
FOR i = 1 TO 5
thisform.oleRTF1.textRTF = EVALUATE("cRtfText" + ALLTRIM(STR(i)))
thisform.command2.Click()
thisform.command3.Click()
thisform.command4.Click()
ENDFOR
ENDPROC
PROCEDURE command2.Click
IF thisform.y_Counter < 6
thisform.oleRTF1.textRTF = EVALUATE("cRtfText" + ALLTRIM(STR(thisform.y_Counter)))
thisform.y_Counter = thisform.y_Counter + 1
ENDIF
ENDPROC
ENDDEFINE