Saving formatted text in the Firebird database

Asked

Viewed 1,114 times

2

I know you have a similar question to that, but it’s for tag C#

  • Has with Save formatted text in a TRichEdit in the Firebird?
  • What would be the data type of field that makes this recording possible?
  • The text of a Trichedit is still a normal string right? It has the tags of the format but it is a string in the same...

  • More if I save the TRichEdit in the bank and asked to show on another TRichEdit it does not show formatted.

  • 1

    I use a component of the Jedi library (Jvdbrichedit) that does this work transparently. It also has a Jvrichedittohtml.

  • I will need to uninstall Rxlib to install JEDI?

  • 1

    Rxlib and JEDI are independent you can have both installed, I advise using the JEDI.

  • I couldn’t install the Jedi...

Show 1 more comment

1 answer

1


It has to save the text of a formatted Richedit in any database or file. To save to database, you should preferably use the field type Blob.

In Firebird, there is Blob Text and Blob Binary. In this case, use the Blob Binary.

See below for the code to save the contents of a Trichedit to a Tblobfield using a Query in Delphi:

procedure TForm1.BtnSalvarRichTextEmBlobClick(Sender: TObject);
var M: TMemoryStream;
begin
  M := TMemoryStream.Create;
  try
    RichEdit.Lines.SaveToStream(M); //salvar o RichEdit em stream

    //Gravar blob na tabela via SQL
    QWrite.SQL.Text := 'insert into Tabela1 (ID, Rich) values (:ID, :Rich)';
    QWrite.ParamByName('ID').AsInteger := 1;
    QWrite.ParamByName('Rich').LoadFromStream(M, ftBlob);
    QWrite.ExecSQL;

  finally
    M.Free;
  end;
end;

See now how would be the function to load this already saved record in table back to Richedit:

procedure TForm1.BtnCarregarDoBancoParaRichTextClick(Sender: TObject);
var M: TMemoryStream;
begin
  //Carregar a Query
  QLoad.SQL.Text := 'select Rich from Tabela1 where ID = :ID';
  QLoad.ParamByName('ID').AsInteger := 1;
  QLoad.Open;

  M := TMemoryStream.Create;
  try
    TBlobField( QLoad.FieldByName('Rich') ).SaveToStream(M); //salvar o field em um stream
    M.Position := 0; //esta linha é necessária pois ao salvar o stream ele estará na posição final
    RichEdit.Lines.LoadFromStream(M); //carregar o stream para o RichEdit
  finally
    M.Free;
  end;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.