Encoding, WTF

General TRichView support forum. Please post your questions here
Post Reply
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Encoding, WTF

Post by elGringo »

Hello,

trying to save in HTML like this

Code: Select all

rve.SaveHTMLToStreamEx(ss,'','','','','','', [rvsoUTF8,rvsoUseCheckpointsNames, rvsoUseItemImageFileNames]);
english text ok, but russian, for example word "Привет" is saved like

Code: Select all

<p>ПРивет</p>
WTF?

Regards,
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Encoding, WTF

Post by Sergey Tkachenko »

This is 'ПРивет' in UTF-8 encoding. It must be displayed correctly in browsers.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: Encoding, WTF

Post by elGringo »

:wink: Ok! Thanks!
Just i do component that is switching from rve to htmlMemo and back, so when i switch to html, in spite of <p>Привет</p> it is visible UTF - no way to fix it?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Encoding, WTF

Post by Sergey Tkachenko »

How do you switch to htmlMemo? Please post code, I'll correct it.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: Encoding, WTF

Post by elGringo »

there is some button, on click it saves to db, makes invisible rve or memo (depends on what is visible now), then loading back to memo and rve

save in db

Code: Select all

procedure TTestsRvePanel.UpdateHTMLContenInDB;
var htmlContent:string;
    ss:TStringStream;

begin

 if rve.Visible then begin

     ss:=TStringStream.Create;
     try
      ss.Position:=0;
      rve.DeleteUnusedStyles(True, True, True);
      rve.ClearUndo;
      rve.SaveHTMLToStreamEx(ss,'','','','','','', [rvsoUTF8,rvsoUseCheckpointsNames, rvsoUseItemImageFileNames]);
      htmlContent:=ss.DataString;
     finally
     ss.Free;
     end;


 end else if Memo.Visible then htmlContent:=memo.Lines.Text;

 //update HTML content in descendants
 if Assigned(FOnUpdateHTMLContent) then FOnUpdateHTMLContent(htmlContent);

end;
loading

Code: Select all

procedure TTestsRvePanelQuestion.LoadHTMLContentFromDB();
var myOwner:TTestsMF;
    tempDir: string;
    randomFilePath: string;
    qSelectHTMLContent:TFDquery;
    clientTempDir: string;
    //RVHTMLViewImporter:TRVHTMLViewImporter;
     addEditForm:TTestsAddEditForm;
begin

 myOwner:=(Self.Owner.Owner.Owner as TTestsMF);
 addEditForm:=(Self.Owner as TTestsAddEditForm);

 qSelectHTMLContent:=TFDquery.Create(Self);
 try

  with qSelectHTMLContent do begin

    Connection:=myOwner.FDConnection_ExternalConnect;
    qSelectHTMLContent.SQL.Text:='SELECT * FROM database.testquestions where id=:id';
    Params.ParamValues['id']:=addEditForm.questionID;//  FQuestionID;
    Disconnect(); Open;
    Memo.Lines.Text:=FieldByName('htmlContent').AsString;
    Close;

           //filling rve from  temp file
            try
               tempDir:=ExtractFilePath(Application.ExeName)+'files\temp';
               TDirectory.CreateDirectory(tempDir);
               randomFilePath:=tempDir+'\'+ inttostr(Random(1000000))+'.html';
               Memo.Lines.SaveToFile(randomFilePath);


                RVAControlPanel.InitImportPictures(nil, nil);
                rve.OnImportPicture := RVAControlPanel.DoImportPicture;
                RVHTMLViewImporter.LoadFromFile(randomFilePath,rve);

                RVAControlPanel.DoneImportPictures;
                rve.OnImportPicture := nil;
                //RvHtmlImporter.LoadHtml(randomFilePath);
                rve.FormatAll;

            finally
            if TFile.Exists(randomFilePath) then
            TFile.Delete(randomFilePath);
            end;



  end;

 finally
 qSelectHTMLContent.Free;
 end;

end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Encoding, WTF

Post by Sergey Tkachenko »

Try creating TStringStream with UTF=8 encoding:

Code: Select all

ss :=  TStringStream.Create('', TEncoding.UTF8)
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

Re: Encoding, WTF

Post by elGringo »

Thanks, but didn't help. Nevermind for the moment.
Post Reply