Page 1 of 1

EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 6:15 pm
by loulou2522
Here is my programm wich show the problem
Before version PB 10 LTS all was good

Code: Select all

Declare.l OpenWindow_2()
Declare Window_2_Events(event,GadgetID)
Global.l histo_0
Global.l Window_2
Global.l quitform2 = #False
Global.l Eventdeux,WindowIDdeux,GadgetIDdeux ,EventTypedeux
Global Button_6

Procedure WindowCallback(WindowID,Message,wParam,lParam) 
  ReturnValue=#PB_ProcessPureBasicEvents  
  If Message=#WM_CTLCOLORSTATIC Or Message=#WM_CTLCOLOREDIT Or Message=#WM_CTLCOLORLISTBOX  
    ReturnValue=PVDynamic_ColorGadget(lParam,wParam)  
  EndIf  
  ProcedureReturn  ReturnValue  
EndProcedure 

Procedure.l OpenWindow_2()
  Window_2 = OpenWindow(#PB_Any, 0, 0, 1090, 700, "ESSAI",#PB_Window_MinimizeGadget | #PB_Window_SizeGadget| #PB_Window_Invisible|#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If Window_2
    SetWindowCallback(@WindowCallback(), Window_2)
     HideWindow(Window_2,1)
    HISTO_0= EditorGadget(#PB_Any, 320, 550, 600, 130, #PB_String_ReadOnly|#PB_Editor_WordWrap)
   SetGadgetColor(HISTO_0, #PB_Gadget_BackColor,RGB(232,250,255) )
    SendMessage_(GadgetID(HISTO_0), #EM_SETTARGETDEVICE, 0, 0); <= 0 = WordWrap
    SendMessage_(GadgetID(HISTO_0),  #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
      Button_6 =ButtonGadget(#PB_Any, 240,  650, 160, 30, "Cliquez pour visualisation")
     HideWindow(Window_2,0)
    ProcedureReturn WindowID(Window_2)      
  EndIf 
 
  
EndProcedure 

Procedure Window_2_Events(event,GadgetID)
  Select event
    Case #PB_Event_CloseWindow
      CloseWindow(Window_2)
    Case #PB_Event_Gadget
      Select GadgetID
        Case button_6
          curent_user.s="toto"
          text.s ="{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1036{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\colortbl ;\red0\green64\blue128;}{\*\generator Riched20 10.0.22621}\viewkind4\uc1\pard\sl276\slmult1"
          text+ "\pard\sl276\slmult1\cf1\b\f0\fs22\lang12"+"\cf1\b"+Chr(32)+dd4+Chr(32) +"\cf0\b0"+ " Cr\u233?ation mandat par "+ current_user+  "\cf0\b0\par" 
        Debug "Variable text = " + text
 SetGadgetText(Histo_0,text)
       Debug "Champ résultat editor =" + GetGadgetText(histo_0)
      EndSelect
  EndSelect


EndProcedure 


If OpenWindow_2()
  quitform2=0
  Repeat
   SetWindowCallback(@WindowCallback())
    quitForm2=0
    Eventdeux = WaitWindowEvent() ; This line waits until an event is received from Windows
    WindowIDdeux = EventWindow()  ; The Window where the event is generated, can be used in the gadget procedures
    GadgetIDdeux = EventGadget()  ; Is it a gadget event?
    EventTypedeux = EventType()   ; The event type
                                  ;  
    Select Eventdeux 
        
      Case #PB_Event_Gadget,#PB_Event_Menu
        If WindowIDdeux = Window_2
          Window_2_Events(Eventdeux,GadgetIDdeux) 
        EndIf
      Case #PB_Event_CloseWindow
        If WindowIDdeux = Window_2
          MessageRequester(""+Space(80), "Abandon Application à  votre demande!.......",  #MB_OK|#MB_ICONERROR|#MB_SYSTEMMODAL)
          quitform2=1                    
        EndIf 
    EndSelect
  Until quitForm2=1 
Else 
  MessageRequester("","Impossible de créer la fenêtre de saisie")
EndIf 
My problem is the following
I want to pass the value of var text in gadegteditor and the result was the following
Variable text = {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1036{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\colortbl ;\red0\green64\blue128;}{\*\generator Riched20 10.0.22621}\viewkind4\uc1\pard\sl276\slmult1\pard\sl276\slmult1\cf1\b\f0\fs22\lang12\cf1\b 0 \cf0\b0 Cr\u233?ation mandat par 0\cf0\b0\par
Champ résultat editor =0 Création mandat par 0
If someone can help me ?

Re: EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 6:54 pm
by charvista
It would be probably a little easier to help you to find the error if you provide us a runable code.
PVDynamic_ColorGadget() is missing here...

Re: EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 8:00 pm
by loulou2522
in MY FIRST POST the code is runable.
Thanks

Re: EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 8:54 pm
by charvista
No, it is not runable because it stops at PVDynamic_ColorGadget(), this procedure is missing.

Anyway, I probably found the problem, a very common problem.
You wrote curent_user.s="toto", it had to be current_user.s="toto" (with two R !) :mrgreen:

To avoid this kind of problem, it is VERY highly recommended to ALWAYS use EnableExplicit at the top of the program, it forces you to declare the variables and so the compiler can detect the spelling mistakes in the variable names. :wink:

Re: EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 9:26 pm
by ChrisR
Yes, your code in the 1st post is not runable, PVDynamic_ColorGadget() procedure is missing!

Otherwise, deletes ALL .l (long) declarations variables, it will already be better for SetWindowCallback(@WindowCallback(), Window_2), whitout Invalid Memory Access.
And deletes the second SetWindowCallback, it has no place in the event loop.

Re: EditorGadget Problem with RTF

Posted: Wed Apr 10, 2024 9:48 pm
by infratec

Code: Select all

SendMessage_(GadgetID(Histo_0), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
https://www.purebasic.fr/english/viewto ... 10#p605710

Re: EditorGadget Problem with RTF

Posted: Thu Apr 11, 2024 1:40 pm
by Fred