RichEdit Delphi text mess up while writing to PostgreSQL database

0

I have tried almost everything.

I have a system in DelphiXe6 with PostgreSQL, in it I have some Text type fields that I need to write formatted text (bold, italic, background color, etc.) type word, it works blz, except when I save the text first time it writes correctly, but if I edit the text it writes a lot of ??????????????? questions messing everything up. The way I load the text in the editor is below:

  if (zqrOrcItens.RecordCount = 0) then
  begin
    TFuncoes.pMensagem('Não existem itens na lista para editar');
    Exit;
  end;

  fdm.Salvar := False;
  fdm.RichStream := TStringStream.Create('');
  zqrOrcItensTexto.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
    zqrOrcItens.Edit;
    fdm.RichStream.Position := 0;
    zqrOrcItensTexto.LoadFromStream(fdm.RichStream); // AsString := fdm.RichStream.DataString;
    zqrOrcItenstexto_puro.AsAnsiString := fdm.TextoPuro;
    zqrOrcItens.Post;
    fdm.zConecta.Commit;
  end;
  FreeAndNil(fdm.RichStream);

I save the formatted text and the plain text so as not to lose what was typed, the plain text writes in a good, but the formatted mess with ?????????????

Damn time I chose RichEdit to save texts, but this system has many years and at the time was the one that had the option, the base is already loaded with these texts and can not edit everything and transform into html

I need a hint of how to work with RichEdit and not have this problem

I have tested many types of Charsets today using UTF8, which should solve the problem, but it did not solve.

    
asked by anonymous 27.06.2018 / 16:15

1 answer

1

The problem of writing this is the type of your field in the database. Instead of using the TEXT type use the BYTEA type. To date I've never had problems with this type and RichEdit, I even use it with images and full formatting.

To record I use just this:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: TMemoryStream;
begin
  s := TMemoryStream.Create;
  RichEdit1.Lines.SaveToStream(s);

  s.Seek(0, soFromBeginning);

  FDQuery1.Edit;
  FDQuery1CampoByteA.LoadFromStream(s);
  FDQuery1.Post;
end;
    
30.06.2018 / 06:08