Page 1 of 1

Encoding, WTF

Posted: Sat Jul 08, 2017 9:54 am
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,

Re: Encoding, WTF

Posted: Sat Jul 08, 2017 9:38 pm
by Sergey Tkachenko
This is 'ПРивет' in UTF-8 encoding. It must be displayed correctly in browsers.

Re: Encoding, WTF

Posted: Sun Jul 09, 2017 9:15 am
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?

Re: Encoding, WTF

Posted: Sun Jul 09, 2017 1:29 pm
by Sergey Tkachenko
How do you switch to htmlMemo? Please post code, I'll correct it.

Re: Encoding, WTF

Posted: Sun Jul 09, 2017 9:39 pm
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;

Re: Encoding, WTF

Posted: Wed Jul 12, 2017 12:16 pm
by Sergey Tkachenko
Try creating TStringStream with UTF=8 encoding:

Code: Select all

ss :=  TStringStream.Create('', TEncoding.UTF8)

Re: Encoding, WTF

Posted: Sat Jul 15, 2017 6:14 am
by elGringo
Thanks, but didn't help. Nevermind for the moment.