Hello All Guru
I am developing software where I want to use "Hindi" (UTF8) and using RICHEDITBOX control.
For entry/saving and display in grid it shows correct values. At the time of editing when values flow into the RICHEDITBOX control it display all "Garbage" Charecter.
Please guide me how to get the correct value in RICHEDITBOX instead of garbage.
Any guidance is much appreciated.
Regards
Hemant
Below is my code
This is define in my main function
REQUEST HB_CODEPAGE_UTF8
HB_CDPSELECT("UTF8")
// HB_SETTERMCP("UTF8")
SET CODEPAGE TO UTF8
prdgrp.prg
#include "
oohg.ch"
#include "
xprtoohg.ch"
#include "
hbextcdp.ch"
FUNCTION prdgrp_Master()
LOCAL aCols := { {"Product Group Name", 300, "pgname"} }
LOCAL cHindiText := "नमस्ते हिन्दी"
// MsgInfo( cHindiText+" Lenght UTF-8 "+ ValToPrg(hb_utf8Len(cHindiText))+" Normal "+ValToPrg(len(cHindiText)), "Checking Core UTF-8 Text Support" )
IF IsWindowActive(frm_xspgmast)
DoMethod("frm_xspgmast", "SetFocus")
RETURN NIL
ENDIF
DEFINE WINDOW frm_xspgmast AT 100,500 WIDTH 450 HEIGHT 500 TITLE "Product Group Master" CHILD NOMAXIMIZE BACKCOLOR XPRT_BACKCLR
ON KEY ESCAPE ACTION (frm_xspgmast.Release)
@ 10,10 LABEL lblS VALUE "Search:" WIDTH 60
@ 10,80 TEXTBOX txtSearch WIDTH 250 ON CHANGE RefreshGrid("xspgmast", aCols, "frm_xspgmast", This.Value)
@ 45,10 GRID grdData ;
WIDTH 410 HEIGHT 350 ;
FONT 'Arial';
HEADERS {"Group Name", "ID"} ; // Added ID Header
WIDTHS {300, 0} ; // Width 0 hides it
ON DBLCLICK Area_Form( GetGridId("frm_xspgmast", "grdData") )
@ 410,10 BUTTON btnAdd CAPTION "Add" ACTION Area_Form(0) WIDTH 80
@ 410,100 BUTTON btnEdit CAPTION "Edit" ;
ACTION Area_Form( GetGridId("frm_xspgmast", "grdData") ) WIDTH 80
@ 410,190 BUTTON btnDel CAPTION "Delete" ;
ACTION Area_Delete() WIDTH 80
frm_xspgmast.btnAdd.Enabled := AppHasPermission( "MASTER_ADD" )
frm_xspgmast.btnEdit.Enabled := AppHasPermission( "MASTER_EDIT" )
frm_xspgmast.btnDel.Enabled := AppHasPermission( "MASTER_DELETE" )
END WINDOW
RefreshGrid("xspgmast", aCols, "frm_xspgmast")
Activate Window frm_xspgmast
RETURN NIL
STATIC FUNCTION Area_Delete()
LOCAL nId := GetGridId("frm_xspgmast", "grdData")
LOCAL aCols := { {"Group Name", 300, "pgname"} }
IF nId > 0 .AND. MsgYesNo("Are you sure you want to delete?")
IF DB_Delete("xspgmast", "id=" + hb_ntos(nId))
RefreshGrid("xspgmast", aCols, "frm_xspgmast")
ENDIF
ENDIF
RETURN NIL
STATIC FUNCTION Area_Form(nId)
LOCAL cName := ""
LOCAL cTitle := IF(nId == 0, "Add Product Group", "Edit Product Group")
LOCAL hWndTxt := 0
local txtName := ""
IF nId > 0
cEditName := DB_GetOne("SELECT pgname FROM xspgmast WHERE id=" + hb_ntos(nId))
cName := alltrim(cEditName) // HB_StrToUTF8( hb_Translate( alltrim(cEditName), "EN", "UTF8" ) ) //DB_GetOne("SELECT pgname FROM xspgmast WHERE id=" + hb_ntos(nId))
msginfo(cEditName+" - "+cName)
ENDIF
DEFINE WINDOW frmEdit AT 300,525 WIDTH 400 HEIGHT 200 TITLE cTitle MODAL BACKCOLOR XPRT_BACKCLR
@ 30,20 LABEL lbl1 VALUE "Group Name: " WIDTH 100
// Swap out the keyword TEXTBOX for RICHEDITBOX
@ 30, 100 RICHEDITBOX txtName ;
VALUE "" ;
WIDTH 200 ;
HEIGHT 24 ; // Give it a single-line height profile
FONT "Arial" ;
SIZE 11 ;
MAXLENGTH 100;
NOVSCROLL NOHSCROLL
// The save button calls GetControlHandle() to fetch the live text data via our custom C block
@ 100,130 BUTTON btnSave CAPTION "Save" ;
ACTION Group_Save(nId, GetProperty("frmEdit","txtName","Value")) WIDTH 80
@ 100,220 BUTTON btnCan CAPTION "Cancel" ACTION ThisWindow.Release WIDTH 80
END WINDOW
IF nId > 0
SetProperty( "frmEdit", "txtName", "Value", cName )
ENDIF
ACTIVATE WINDOW frmEdit
RETURN NIL
STATIC FUNCTION Group_Save(nId, cName)
LOCAL aCols := { {"Product Group Name", 300, "pgname"} }
cName := AllTrim(cName)
IF Empty(cName) ; MsgStop("Name required") ; RETURN NIL ; ENDIF
// Pass the clean cName string straight through
IF CheckDuplicate("xspgmast", "pgname", cName, nId, "id")
MsgStop("Product Group Name already exists")
RETURN NIL
ENDIF
// Both commands now pass cName directly without extra encoding wrappers
IF nId == 0
DB_Insert("xspgmast", {{"cmpid", g_cmpcode}, {"pgname", cName}})
ELSE
DB_Update("xspgmast", {{"pgname", cName}}, "id=" + hb_ntos(nId))
ENDIF
DoMethod("frmEdit", "Release")
RefreshGrid("xspgmast", aCols, "frm_xspgmast")
RETURN NIL