Reputation: 1341
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;
Upvotes: 1
Views: 1972
Reputation: 14842
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 TStream
s 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.)
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.
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
).
ADODB_TLB
(it will be used by MHTBuilder).MHTBuilder
instead.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).
Upvotes: 2
Reputation: 1857
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:
By using TStream
from desired unit explicitly.
var
S1: ADODB_TLB.TStream;
S2: Classes.TStream;
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)
Upvotes: 3