CONCATENATE CONTENT FROM STREAMS

  • I have a field in a database table that holds the contents of a WPRichText component with tags as Stream

    I would like to concatenate the streams of a select on that field:

    "Select TOP 5 STREAM_TEXT From Table"

    And display these five contents on a WPRichText

    Stream := TMemoryStream.Create;

    TempStream := TMemoryStream.Create;

    WPRichTextResult.ReadOnly := False;

    WPRichTextResult.Clear;

    WPRichTextResult.AsString := '';

    while not dmSGA.QBusca.Eof do

    begin

    TBlobField(dmSGA.QBusca.FieldByName('STREAM_TEXT')).SaveToStream(TempStream);

    Stream.CopyFrom(TempStream, 0);

    Stream.seek(0, soEnd);

    Stream.CopyFrom(TempStream, 0);

    WPRichTextResult.LoadFromStream(Stream); // load stream contents into rich

    dmSGA.QBusca.Next;

    end;

    Stream.Free;

    TempStream.Free;

    • Offizieller Beitrag

    RTF Format does not allow concatenation but you can use LoadFromStream to append text:

    The boolean variable first makes sure the first text is loaded completely, including page format and other elements. The other texts are just appended.

  • Than you very much, but it does not works, unfortunately.

    I took th decision to transform STREAMS to Strings and get tet with formating tags. After that concatenate the strings appending one after other.

    Wich methods is the appropriated to display that text?

  • Hallo There , back to this situation again after a while, so thanks for answers.

    Ok such method don't worked to me. So as I need to get the text of the stream I wasted some time working on transform the stream to String function that works pretty well!

    Now that I got the String from stream how to Append each RTF formated String on WPRichText ? I tried Fast Add but it treats only pure text

    prp.Text := StreamToString(Stream);

    WPLaudoLabDetalhe.FastAddText(prp);


    the function above works pretty fine !


    Now Calling the method:

    Code
    first := true;
    while not dmSGA.QBusca.Eof do
    begin
           TBlobField(dmSGA.QBusca.FieldByName('LAUD_TEXTO')).SaveToStream(Stream);
           Stream.Position := 0;
            WPLaudoLabDetalhe.LoadFromString(StreamToString(Stream),'AUTO',first); 
            dmSGA.QBusca.Next;
            first := false;
    end;

    It just dont works !

    Should be another method to threat RTF tags?


    Thank you very much1

    • Offizieller Beitrag

    If the RTF streams are alright, LoadFromStream will append a file to the text in memory.

    LoadFromString is not required, it just calls LoadFromStream internally.

    Thats my suggestion:

    Note the TempStream.Clear - it was missing the the code above.