Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?
$720 in referrals so far!

About/Contact

Steve Trefethen

Steve Trefethen is a Software Architect and Director of Software Training at Falafel Software in Capitola, CA. You can reach Steve here.

All opinions you read here are Steve's own and are not necessarily those of Falafel Software.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
If you're new here, you may want to subscribe to my RSS feed, follow me on Twitter, or subscribe via email. Thanks for visiting!

Problems with Imported Type Library Declarations in Delphi

November 01 2004 9:16PM

Since I've been working on the HTML/ASP.NET designer one of the things I've noticed over the years is that our type library import tool improperly imports certain declarations particularly when it comes to const (or [in]) parameters.  I've run into method declarations where at least one parameter is declared as “var” when in fact it should have been declared as “const”.  At best, this results in no error but more frequently results in an application AV.  I've talked to our type library gurus but unfortuantely this didn't get addressed in Delphi 2005 thus our importer still suffers this problem.  Don't worry I'll keep at it.  :)

Anyway, if you have imported a type library and you are pulling your hair trying to call a method on some object try double checking that the method in question is actually declared correctly.

For example, IWebBrowser2.Navigate is declared as follows once imported using tlibimp.exe:

procedure Navigate(const URL: WideString; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant); safecall;

Notice that the last four parameters are declared as “var” when in fact they should have been declared as “const”.  If you try using this method you could run into problems as a result of this misdeclaration.  The actual declaration should be:

procedure Navigate(const URL: WideString; const Flags: OleVariant; const TargetFrameName: OleVariant; const PostData: OleVariant; const Headers: OleVariant); safecall;

If you take a look at the declaration here on MSDN you'll notice that all of the parameters are specificed as [in] in the Parameters section so it doesn't make a lot of sense for them to be declared as “var“ in Pascal.  So, if you can't figure out why you're unable to call an interface method from Delphi from a type library that you've imported double check that the method is in fact declared correctly.

On a bit of a side note, I generated the MSHTML.pas file that we use in the IDE with the following tlibimp.exe command line:

tlibimp -Hs- -Hr- -Fe- \WINNT\SYSTEM32\mshtml.tlb

If you are running into problems specifically with MSHTML.pas please leave a comment and if there is sufficient interest I'll look to post our version of MSHTML.pas to CodeCentral.

FacebookDel.icio.usDigg It!

Tags:

Comments are closed