What is the safe way to work with TRicheEdit Database?

0

I'm asking this question because the days I'm having a huge headache with this RichEdit junk, time it saves correct time it saves a lot of ???????????? in the base ... I know it may be an error in the conversion of characters but the detail is that the problem is intermittent.

If it is the first time I record it it writes correctly

If it's editing it records a bunch of strange, Chinese-type characters.

If I clean the base and insert the text again and save it correctly.

Sometimes in the edit it writes correctly.

I'd like to change everything for HTML but it's not feasible, it's years of writing everything in RichEdit because I need formatted text.

The way I'm doing it goes below:

  ...
  fdm.RichStream := TStringStream.Create(fdm.zqrAux_Aet_TextoDiversas.AsAnsiString);
  //fdm.zqrAux_Aet_TextoDiversas.SaveToStream(fdm.RichStream);

  f_richedit := Tf_richedit.Create(nil);
  fdm.RichStream.Position := 0;
  f_richedit.RichEdit.Lines.LoadFromStream(fdm.RichStream);
  TFuncoes.pJustRichEdit(f_richedit.RichEdit, False);
  f_richedit.ShowModal;

  if (fdm.Salvar) then
  begin
    fdm.zqrAux_Aet_Texto.Edit;
    fdm.RichStream.Position := 0;
    fdm.zqrAux_Aet_TextoDiversas.LoadFromStream(fdm.RichStream);//AsString := fdm.RichStream.DataString;
    fdm.zqrAux_Aet_Texto.Post;
    fdm.zConecta.Commit;
  end;
  FreeAndNil(fdm.RichStream); // .Free;
  fdm.zqrAux_Aet_Texto.Close;
  f_richedit := nil;

Look at some "commented out" that I tried to save in other ways, but the problem continues

The database is postgresql, but I think it does not even matter, because it writes text and it is UTF8 and everything as it asks the costume

Does anyone know a safe way to work with this RichEdit?

I say safe because right I do not even know, rs

    
asked by anonymous 03.05.2018 / 20:20

1 answer

0

The right thing would not be to write the contents of f_richedit.RichEdit ??

  fdm.RichStream := TStringStream.Create(fdm.zqrAux_Aet_TextoDiversas.AsAnsiString);
  //fdm.zqrAux_Aet_TextoDiversas.SaveToStream(fdm.RichStream);

  f_richedit := Tf_richedit.Create(nil);
  fdm.RichStream.Position := 0;
  f_richedit.RichEdit.Lines.LoadFromStream(fdm.RichStream);
  TFuncoes.pJustRichEdit(f_richedit.RichEdit, False);
  f_richedit.ShowModal;

  if (fdm.Salvar) then
  begin
    fdm.zqrAux_Aet_Texto.Edit;
    fdm.RichStream.Position := 0;
    fdm.zqrAux_Aet_TextoDiversas.AsString := f_richedit.RichEdit.Lines.Text;
    fdm.zqrAux_Aet_Texto.Post;
    fdm.zConecta.Commit;
  end;
  FreeAndNil(fdm.RichStream); // .Free;
  fdm.zqrAux_Aet_Texto.Close;
  f_richedit := nil;

Edited

I do not know if you've tried but try to do so, you save in Stream, format the text in richedit and then save it again in the stream before saving in DB. When you see the text where you want it, use LoadFromFile.

Note: Leave the PlainText property of richedit as False.

  //fdm.RichStream := TStringStream.Create(fdm.zqrAux_Aet_TextoDiversas.AsAnsiString);
  fdm.zqrAux_Aet_TextoDiversas.SaveToStream(fdm.RichStream);

  f_richedit := Tf_richedit.Create(nil);
  fdm.RichStream.Position := 0;
  f_richedit.RichEdit.Lines.LoadFromStream(fdm.RichStream);
  TFuncoes.pJustRichEdit(f_richedit.RichEdit, False);
  f_richedit.ShowModal;

  {Colocar aqui a função para limpar o fdm.RichStream aqui antes de salvar novamente, não lembro como é}
  f_richedit.RichEdit.Lines.SaveToStream(fdm.RichStream);

  if(fdm.Salvar)then
  begin
    fdm.zqrAux_Aet_Texto.Edit;
    fdm.RichStream.Position := 0;
    fdm.zqrAux_Aet_TextoDiversas.LoadFromStream(fdm.RichStream);//AsString := fdm.RichStream.DataString;
    fdm.zqrAux_Aet_Texto.Post;
    fdm.zConecta.Commit;
  end;

  fdm.zqrAux_Aet_Texto.Close;
  FreeAndNil(fdm.RichStream); // .Free;
  FreeAndNil(f_richedit);
    
03.05.2018 / 20:34