Answers for "Save richedit to mdb"

0

Save richedit to mdb

//Save to stream
stream := TMemoryStream.Create;
stream.Clear;

RichEdit.Lines.SaveToStream(stream);
stream.Position := 0;

//Read from the stream into an AnsiString (rtfString)
if (stream.Size > 0) then begin
    SetLength(rtfString, stream.Size);
    if (stream.Read(rtfString[1], stream.Size) <= 0) then
        raise EStreamError.CreateFmt('End of stream reached with %d bytes left to read.', [stream.Size]);
end;

stream.Free;

//Save to database
sql.FieldByName('rtftext').AsAnsiString := rtfString;
Posted by: Guest on May-20-2021

Browse Popular Code Answers by Language