Home DADE

Switching Databases at Runtime

edited March 2003 in DADE
This is a multi-part message in MIME format.

Comments

  • edited March 2003
    This is a multi-part message in MIME format.
  • edited March 2003
    This is a multi-part message in MIME format.
  • edited March 2003
    This is a multi-part message in MIME format.
  • edited March 2003
    This is a multi-part message in MIME format.
  • edited March 2003
    Hi Waguih,

    I have got the same aplication layout as you described and the same problem
    also (RB 7.02).

    I've solved the dataview db assignment at runtime:

    Code:

    Report.Template.OnLoadStart := LoadReportStreamEvent;

    procedure TForm.LoadReportStreamEvent(Sender: TObject; Stream: TStream);
    var
    AuxStream: TMemoryStream;
    line: string;
    pos: byte;
    begin
    if TestStreamFormat(Stream) <> sofText then Exit;

    Stream.Position := 0;
    auxStream := TMemoryStream.Create;
    try
    while not Stream.EOLF do begin
    line := Stream.NextLine;
    pos := Pos ('DatabaseName = ', line);
    if pos > 0 then
    line := Copy (line, 1, pos+14)+Chr(39)+ "MyDBAlias"+Chr(39);
    line := line+#13#10;
    AuxStream.WriteBuffer(line[1], Length (line));
    end;
    AuxStream.Position := 0;
    Stream.CopyFrom(AuxStream, AuxStream.Size);
    TMemoryStream (Stream).Setsize(AuxStream.Size);
    end;
    finally
    AuxStream.Free;
    end;
    end;

    Of course i am working with text format for the templates.

    But when i open the designer at runtime a still have to manually assign the
    database alias in datasettings dialog because it shows empty. I don't know
    why and the only difference to your implementation has todo with the fact
    that i am creating all the components at runtime. But i am filling the
    properties with all the values i suppose to, as i've seen in the dfm files
    of DBIsam demo.

    MacBar
  • edited March 2003
    That is cool. It is also possible to convert a binary template to ascii text
    first, in order to more easily convert the class names for the objects in
    the dataview to switch between data base types, such as TdaBDEQueryDataview
    to TdaADOQueryDataview. Then save the ascii text down to a binary template,
    all without having to load a report template into a report object. Here is
    an example of this technique:

    http://www.digital-metaphors.com/tips/ConvertBinaryTemplateToASCII.zip

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Hi MacBar,

    Thank you very much for your suggestion. I'm having a problem compiling the
    code you're suggesting though. In my Delphi (7 Ent), properties and methods
    of the TStream object (e.g. EOLF, NextLine) don't seem to be legal. I've
    done thorough searches in all Delphi library source directories, and
    inspected the TStream and all its descendants using the Browser for these
    attributes and cannot seem to be able to find them. Are you using a custom
    descendant of TStream for that?

    Also, from your example, it appears you're attempting to change the
    AliasName itself. In my case, the AliasName remains the same, what changes
    is the path it points to. Will your code work with that too? And if so, I'd
    really like to understand why it would.

    Thanks for your help.

    Waguih

  • edited March 2003
    Hi Jim,

    text
    TdaBDEQueryDataview
    template,

    I forgot to mention some details.

    I am changing object properties of the template while streaming from
    database and as RB imposes binary format in DB case, i am compressing and
    decompressing ascii template to get better binary compression and also to do
    this kind of manipulation without more complications.

    Best regards,
    MacBar
  • edited March 2003
    Hi Waguih,

    the
    methods

    Yes and sorry i forgot to mention it. If you want i can send you the all
    class privatly.

    I'd

    In my case each alias points to a different database so i am managing the
    database switch by switching the db alias at runtime.

    Best regards,
    MacBar
  • edited March 2003
    Hi MacBar,

    Thank you very much for offering your code. That is very nice of you. I'd
    like very much to try it out. My email address is wboctor@hotmail.com.

    Thanks again and I'll let you know how it works out for me.

    Waguih

This discussion has been closed.