Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

How to save report template into database via LoadFromStream and SavetoStream?

edited July 2001 in General
Hi dear,

How i will use stream to save report template. Actually I have created my
own application interface and not using the explorer component because of
the company requirement. So please let me know the way to save report via
streaming.


regards,
Nasir Mahmood Butt

Comments

  • edited July 2001
    Hi Nasir,

    load a stream from the record, the stream loading from a table's field is
    database (component depending) depending (check the documentation), then you
    can load the template from that stream.

    regards,
    Chris Ueberall;
  • edited July 2001
    Hi Chris,

    I have used LoadFromStream and SaveToStream Methods of Template Object but
    it does not load the Report information through LoadFromStream method and
    returns me an error 'Reading Stream Error'. What the method i did to
    implement this streaming technique is paste the Memo control on the form and
    called the method to save Stream information into Memo Control when clicked
    the save menu opiton from the designer and it is successful but it does not
    load the report information from the Memo Control at the time of opening. So
    please let me know why it is happening.


    regards,
    Nasir Mahmood Butt


  • edited July 2001
    Hi Nasir,

    Sorry, but I'm a little bit puzzled about your 'Memo Control'.
    Can you show us some code of your doing.
    What do you want to achieve?

    regards,
    Chris Ueberall;

    but
    and
    clicked
    not
    So
    is
  • edited July 2001

    Hi Chris,


    This code saves report information into stream and then i load memo control
    with that stream but when i load report from saved information into memo
    control, it does not load and give me an error 'Stream Read Error'. I could
    not find out the problem.

    Added Controls on a Form are as listed below:

    1. Memo1

    2. ppReport1

    3. ppDesigner1

    4. Button1 - Caption := Save to Stream

    5. Button2 - Caption := Load From Stream


    Private

    MyMenue: TMainMenu;
    SubMenu: TMenuItem;
    ReportStream : TMemoryStream;

    Procedure ReportSave(Sender : TObject);


    procedure TStreamForm.Button1Click(Sender: TObject);
    begin

    MyMenue:= ppDesigner1.Menu;
    SubMenu:= MyMenue.Items [0];

    if (SubMenu.Items[5].Name = 'mniFileSave') then
    begin
    SubMenu.Items[5].OnClick := ReportSave;
    end;

    ppReport1.Template.New;

    ppDesigner1.Show;

    end;


    procedure TStreamForm.ReportSave(Sender : TObject);
    begin

    ReportStream:= TMemoryStream.Create;
    ppReport1.template.SaveToStream(ReportStream);

    ReportStream.Position := 0;

    Memo1.Clear;
    Memo1.Lines.LoadFromStream(ReportStream);

    ReportStream.Free;

    ShowMessage('Save Report');

    end;


    procedure TStreamForm.Button2Click(Sender: TObject);
    begin

    ppReport1.Template.New;

    ReportStream:= TmemoryStream.Create;
    Memo1.Lines.SaveToStream (ReportStream);

    ReportStream.Position := 0;

    ppReport1.template.LoadFromStream(ReportStream);

    ppDesigner1.Show;

    ReportStream.Free;

    end;



    regards,

    Nasir Mahmood Butt





  • edited July 2001
    Nasir,

    is the template format of type 'ftASCII', otherwise the TMemo wouldn't be
    the right container.
    I would use a file (or any other object ready for storing BLOBs) as
    storage, not a TMemo.
    You can load it into the TMemo for visualizing.

    regards,
    Chris Ueberall;

    control
    could
    Object
    form
    does
    field
  • edited July 2001
    Hi Chris,

    After changing report format to 'ftASCII', now the report is successfully
    saved from stream to database and loaded back properly as well. But is it a
    limitation that we can't perform these steps with report format of
    'ftBinary'? If we can do with this format then please let me know also and
    what are the limitation which must be kept in mind during saving report into
    database from stream and as well as back to loading from database to stream.

    Code example would be higly appreciated.

    regards,
    Nasir Mahmood Butt


  • edited July 2001
    Hi Nasir,

    Sorry, this isn't a limitation of ReportBuilder, this is a limitation of
    TMemo.
    When loading a TMemo, a container for TEXT, the binary will be scrampled,
    that's by design.
    (You may load any executable in notepad and save it to file, good luck).
    There is no need to store a binary report in a TMemo.
    You can use any container designed for binary data as storage, TStream and
    descendants, database BLOB fields, ...
    To load and save from a table's BLOB field, usually you have to create a
    TBlobStream (some databases uses their own BlobStream components, see your
    database documentation).
    There are no other requirements or knowledge necessary, standard stream
    handling, no secrets.

    regards,
    Chris Ueberall;

    a
    into
    stream.
This discussion has been closed.