FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour METHOD SaveToFile of trichedit is wrong ?
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
METHOD SaveToFile of trichedit is wrong ?
Posted: Mon Apr 25, 2016 12:49 AM
If I open testrtf.rtf from testrtf I can see the file

but if I change and insert a word and close the window it ask me if I want save the file
I press ok and it ask me if "Do you want to overwrite it"

I press ok

when I reopen the file I cannot see nothing with testrtf.exe
because it save as text
if I open the file with windows notepad I can see the file as text and I saw it lose the format rtf

why ?
perhaps the METHOD SaveToFile is wrong ?



Code (fw): Select all Collapse
METHOD SaveToFile( cFileName ) CLASS TRichEdit

   DEFAULT cFileName := ::cFileName

   if Empty( cFileName )
      MsgAlert( "No filename provided to save the richedit text" )
      return nil
   endif

   if File( cFileName )
      if MsgYesNo( cFileName + " already exists" + CRLF + ;
                   "Do you want to overwrite it ?" )
         MemoWrit( cFileName, ::GetText() )
      endif
   else
      MemoWrit( cFileName, ::GetText() )
   endif

return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: METHOD SaveToFile of trichedit is wrong ?
Posted: Mon Apr 25, 2016 04:10 AM
Silvio

Method SaveToFile is correct
Save file as Text plain.
You are change extension of cFileName to save, or
Code (fw): Select all Collapse
static function Save()

   local cFile := cGetFile( "Rich Text Format (*.rtf) |*.rtf|" + ;
                            "Only Text Format (*.txt) |*.txt|", ;
                            "Please write a filename", nGetFileFilter(),, .t. )

   if !Empty( cFile )
      cFile := Upper( cFile ) + If( ! "." $ cFile, If( nGetFileFilter() == 1, ".RTF", ".TXT" ), "" )
       
      If  nGetFileFilter() == 1
         oRTF:SaveToRTFFile( cFile )
      endif
      If  nGetFileFilter() == 2
         oRTF:SaveToFile( cFile )
      endif
      oRTF:SetClear()
   endif

return nil


Regards
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: METHOD SaveToFile of trichedit is wrong ?
Posted: Mon Apr 25, 2016 03:58 PM
on testrtf.prg there is another big error

1. Open 2 window child and on each write the word "HOME"
2. then select the word home on a window child and press the size of the font

3. you 'll see also the get ( size of font) of the other window child is moved and the word not change the size

4. then you close the first window child created and try to change size on word home selected ... not run

5. then you must close also the second window child and reopen a new window child

6. write "home" and selected it and then you can change the size ....

why happen this ? because the rtf is called ortf to all window child

we must change it from ortf to oWndMain:oWndActive:TMdiChild:oControl to have the current rtf

sample :

Function WndChild()
LOCAL oWnd
oWnd := oWndMain:oWndActive:TMdiChild:oControl
RETURN oWnd

then

@ .38, 74.2 GET oSize VAR nSize OF oWnd:oBar ;
FONT oFont SIZE 20, 19 PICTURE "99" ;
SPINNER MIN 6 MAX 99 ;
ON CHANGE ( WndChild():SetFontSize( oSize:VarGet() ), WndChild():SetFocus() )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion