1

I have done this as described below:

uses CDO_TLB, ADODB_TLB; _Stream defined in ADODB_TLB unit (Active Data Objects). IMessage, > I Configurationin in CDO_TLB unit (Collaboration Data Objects). If not already created use the Import Type Library as follows and create: CDO_TLB = C:\WINDOWS\system32\cdosys.dll
ADO_TLB = C:\Program Files\Common Files\System\ado\msadoxx.dll - xx version number

Now I get following error:

    [Fehler] Unit1.pas(1650): Inkompatible Typen: 'ADODB_TLB.TStream' und 'Classes.TStream'
    [Fehler] Unit1.pas(1651): Inkompatible Typen: 'ADODB_TLB.TStream' und  'Classes.TStream'
    [Fehler] Unit1.pas(1655): Inkompatible Typen: 'Classes.TStream' und 'ADODB_TLB.TStream'
    [Fehler] Unit1.pas(1656): Inkompatible Typen: 'Classes.TStream' und 'ADODB_TLB.TStream'
    [Fehler] Unit1.pas(1720): Inkompatible Typen: 'ADODB_TLB.TStream' und 'Classes.TStream'
    [Fehler] Unit1.pas(1724): Inkompatible Typen: 'Classes.TStream' und 'ADODB_TLB.TStream'

At this statement:

    SpecStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SpecSheet'), bmRead);
    SaftyStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SaftySheet'), bmRead);

I know that I have change the Type library by importing the TLBs. But How can I still use both Classes?

Here is my code, that part that is necessary only: (The lines commended out with //we makes an error.)

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, Grids, DBGrids, ExtCtrls, DBCtrls, MemDS, DBAccess,
      MyAccess, MyDacVcl, StdCtrls, frxClass, frxDesgn, frxDBSet, frxExportPDF,
      jpeg, ComCtrls, SBCookieMgr, SBSimpleSSL, SBHTTPSClient, SBConstants,
      SBHTTPCRL, SBHTTPOCSPClient, SBHTTPCertRetriever,  SBX509,
      SBSSLClient, SBTypes, SBUtils, SBCustomCertStorage, SBCertValidator,
      OleCtrls, SHDocVw ,Wininet, PDFSplitMerge_TLB,
      ActiveX, // IMalloc
      ShlObj, SBArcBase, SBArcZip, // CSIDL_-Konstanten
      ShellAPI; // SHGetSpecialFolderLocation() und SHGetPathFromIDList()


    type
      ...

    implementation

    {$R *.dfm}

    uses  RegExpr, CDO_TLB, ADODB_TLB;

    ..

    procedure TForm1.Button7Click(Sender: TObject);
    var
      oldTabSheet: TTAbSheet;
      SpecStream, SaftyStream: TStream;

      MyAN: string;
      MyLief: String;

    begin
      oldTabSheet := pageControl1.ActivePage;
      pageControl1.ActivePage:= TabSheet5;
      //WebBrowser1.Navigate(PrgDirName+'\laborbedarf.pdf');
      //WebBrowser1.Quit;
      //Radiobutton1.Checked:=NOT(radiobutton1.Checked);
      //Radiobutton2.Checked:=NOT(radiobutton2.Checked);

        MyAN := MyQuery1.FieldByName('ArtikelNummer').AsString;
        MyLIEF := MyQuery1.FieldByName('Lieferant').AsString;
        if NOT((MyAN = NULL) or (MyAN = ''))  then
          begin
          (* ---------------------------------------------------------- LIEFERANT 1 ---*)

          if MyLIEF = DBGrid1.Columns[11].PickList[0] then
            begin
            MyQuery9.SQL.Text:='select * from stoff WHERE   RecID = :Old_RecID';
            MyQuery9.ParamByName('Old_RecID').AsInteger := MyQuery1.FieldByName('RecID').AsInteger;
            MyQuery9.Execute;
    //we        SpecStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SpecSheet'), bmRead);
    //we        SaftyStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SaftySheet'), bmRead);
            MyStream2S := TMemoryStream.Create;
            MyStream3S := TMemoryStream.Create;
            MyStream2S.Clear; MyStream3S.clear;
    //we        MyStream2S.LoadFromStream(SaftyStream );
    //we        MyStream3S.LoadFromStream(SpecStream );

            if RadioButton1.Checked then
              begin
                try

                  DeleteFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  MyStream2S.SaveToFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  WebBrowser1.Navigate(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  Radiobutton1.Checked:= false;
                  Radiobutton2.Checked:= true;

                except
                  end;

                try
                  DeleteFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  MyStream3S.SaveToFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  WebBrowser1.Navigate(GetTempDirectory+'Spezifikation_tmp.pdf');
                  Radiobutton1.Checked:= true;
                  Radiobutton2.Checked:= false;


                except
                  end;

              end
            else if RadioButton2.Checked then
              begin
                try

                  DeleteFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  MyStream3S.SaveToFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  WebBrowser1.Navigate(GetTempDirectory+'Spezifikation_tmp.pdf');
                  Radiobutton1.Checked:= true;
                  Radiobutton2.Checked:= false;

                except
                  end;

                try

                  DeleteFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  MyStream2S.SaveToFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  WebBrowser1.Navigate(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  Radiobutton1.Checked:= false;
                  Radiobutton2.Checked:= true;

                except
                  end;

              end;


            end
            (* ---------------------------------------------------------- LIEFERANT 2 ---*)
          else
            if MyLIEF = DBGrid1.Columns[11].PickList[1] then

            begin
            MyQuery9.SQL.Text:='select * from stoff WHERE   RecID = :Old_RecID';
            MyQuery9.ParamByName('Old_RecID').AsInteger := MyQuery1.FieldByName('RecID').AsInteger;
            MyQuery9.Execute;
            //SpecStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SpecSheet'), bmRead);
    //we        SaftyStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SaftySheet'), bmRead);
            MyStream2S := TMemoryStream.Create;
            MyStream3S := TMemoryStream.Create;
            MyStream2S.Clear; MyStream3S.clear;
    //we        MyStream2S.LoadFromStream(SaftyStream );
            //MyStream3S.LoadFromStream(SpecStream );

           Radiobutton1.Checked:= false;
           Radiobutton2.Checked:= true;

            if RadioButton2.Checked then
              begin
                try

                  DeleteFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  MyStream3S.SaveToFile(GetTempDirectory+'Spezifikation_tmp.pdf');
                  if Filesize(GetTempDirectory+'Spezifikation_tmp.pdf') > 5 then
                    WebBrowser1.Navigate(GetTempDirectory+'Spezifikation_tmp.pdf')
                  else
                    WebBrowser1.Navigate(PrgDirName+'\PDFLeer.pdf');

                  Radiobutton1.Checked:= true;
                  Radiobutton2.Checked:= false;

                except
                  ShowMessage(' Kann PDF nicht anzeigen, wurde es nicht geladen weil nicht verfügbar?');
                  end;

                try

                  DeleteFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  MyStream2S.SaveToFile(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf');
                  if Filesize(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf') > 5 then
                    WebBrowser1.Navigate(GetTempDirectory+'Sicherheitsdatenblatt_tmp.pdf')
                  else
                    WebBrowser1.Navigate(PrgDirName+'\PDFLeer.pdf');

                  Radiobutton1.Checked:= false;
                  Radiobutton2.Checked:= true;

                except
                  ShowMessage(' Kann PDF nicht anzeigen, wurde es nicht geladen weil nicht verfügbar?');

                  end;

              end;


            end   ;

        //MyQuery1.Next;
        MyStream3S.Clear;
        MyStream2S.Clear;
        MyStream3S.free;
        MyStream2S.free;

        end
      else
        begin
        ShowMessage('Kein PDF in DB gefunden!');
        end;




    end;
Walter Schrabmair
  • 1,251
  • 2
  • 13
  • 26
  • 1
    I guess you have two units that declare `TStream. But you don't show code in a readable way, and you don't tell us what type any of the variables are. You could help by showing complete code, or at least enough for us to know what everything is. – David Heffernan Jun 15 '14 at 16:48
  • I want to integrate this procedure: [link]http://stackoverflow.com/questions/12690331/create-mht-file-web-archive @David: It works fine before I addes the ADODB_TLB in the uses clause. – Walter Schrabmair Jun 15 '14 at 16:56
  • 1
    I suggest you re-read my comment and follow the advice with a question edit – David Heffernan Jun 15 '14 at 16:57
  • Declare SpecStream as classes.TStream, and the other one. – Sertac Akyuz Jun 15 '14 at 17:03
  • 1
    @SertacAkyuz: Thanks a lot, now I could compile. – Walter Schrabmair Jun 15 '14 at 17:13
  • Far and away your biggest problem is the lack of naming in your code. You can't go on like that. Surely you must realise that types and variables can be given names. – David Heffernan Jun 15 '14 at 19:41
  • 1
    @WalterSchrabmair I suggest you reconsider all your try..excepts. That's not the way to do exception handling. All you're doing is hiding your errors. You should also use try..finally to protect resources. And finally you need to split you code into smaller functions. – Disillusioned Jun 15 '14 at 22:11
  • @CraigYoung I agree to you, but unfurtunately when I want to load another PDF in the Webbrowser it says, that it is used by another process. (The Acrobat reader in the Webbrowser.) THis toggles the files and I can show the desired PDF. I really dont know why. – Walter Schrabmair Jun 16 '14 at 13:06

2 Answers2

3

Obviously you have second declaration of TStream in ADODB_TLB unit, and when you use both ADODB_TLB and Classes in same unit - TStream will be used from last unit it is declared. You can resolve this:

  1. By using TStream from desired unit explicitly.

    var
    S1: ADODB_TLB.TStream;
    S2: Classes.TStream;

  2. By renaming one TStream to something more unique like ADODB_TLB.TStream to ADODB_TLB.TADOStream. I would prefer this way. You can do this by reimporting ADODB_TLB and specify type renaming for TStream (this is selected in import wizard)

VitaliyG
  • 1,837
  • 1
  • 11
  • 11
2

The problem is your interface uses Classes which defines TStream.
And your implementation uses ADODB_TLB which also defines TStream.
NOTE: As Sertac points out, you would also get errors if you included both units in the interface section, but had ADODB_TLB after Classes.

So whenever you use TStream in the interface section of your unit, you're using Classes.TStream. But in the implementation section, that would be ADODB_TLB.TStream, which is why you're getting the errors. The errors also occur when you call a routine in another unit that uses a different type of TStream (such as CreateBlobStream which returns Classes.TStream).

//You declared SaftyStream in the implementation section, so it is ADODB_TLB.TStream.
//But CreateBlobStream returns a Classes.TStream.
//So they are incompatible.
SaftyStream := MyQuery9.CreateBlobStream(MyQuery9.FieldByName('SaftySheet'), bmRead);

//You don't show where you declare MyStream2S.
//I assume interface section, so it is Classes.TStream.
//Classes.TStream.LoadFromStream expects to be given a Classes.TStream
//But SaftyStream is ADODB_TLB.TStream, which is incompatible.
MyStream2S.LoadFromStream(SaftyStream );

The first thing you need to decide in resolving this is which of the two TStreams you actually want to use? (I suspect the one in Classes. As Sertac points out, CreateBlobStream returns a Classes.TStream, so you should use that one.)

Options

  • First consider whether you really need to use ADODB_TLB? Delphi already has wrappers for this type library in ADODB.pas. If you can use it, you would be following "more traditional" Delphi paradigms.

  • If you must code against ADO directly, then I suggest you move the uses ADODB_TLB into the interface section, and before uses Classes. This way the most recent definition of TStream (from Classes) would apply to your whole unit.

  • You can also reference the types with a fully qualified name as in point 1 of VitaliyG's answer. I.e. Classes.TStream

  • However, in this case I wouldn't advise renaming TStream as in point 2 of his answer. The reason is that these are units shipped with Delphi, and other units have dependencies on them. But if the naming conflict were in your own units, then I would definitely suggest choosing more specific names to differentiate the types. And if the types are truly the same thing, then maybe you should rather merge them into a shared third unit.


ADDENDUM

You mentioned in a comment:

I want to integrate this procedure: Create *. Mht-file (Web Archive) It worked fine before I added the ADODB_TLB in the uses clause.

This explains why you added the unit. However, given the naming conflict, and potential for unnecessary headaches: I suggest you rather isolate the functionality into a small dedicated unit (e.g. MHTBuilder.pas).

  • Then your unit won't need to use ADODB_TLB (it will be used by MHTBuilder).
  • Your unit will use MHTBuilder instead.
  • And call a simple function to build the MHT file.

This is closely related to my comment about you needing to split your code into smaller functions. Breaking things down into smaller pieces makes it much easier to manage complexity. Basically you should avoid trying to lump all your functionality and options into a huge method (as you did).

Community
  • 1
  • 1
Disillusioned
  • 14,635
  • 3
  • 43
  • 77
  • 1
    Either your problem identification is wrong, or your wording gives that impression. Even if both of the units have been *used* in the *interface*, as long as 'adodb_tlb' is used after 'classes', there would be the error. That's because 'CreateBlobStream' returns a 'classes.TStream'. (Which BTW indicates there's no doubt about it's the classes' stream that's intended to be used (could also refer to the comments to the question if that was not obvious)). – Sertac Akyuz Jun 15 '14 at 22:24
  • Thanks @SertacAkyuz I've updated my answer to clarify. – Disillusioned Jun 15 '14 at 22:55