Casting a TWebBrowser as a TWinControl

Can anyone tell me why the second cast fails to compile in Delphi 7?

var
  WebBrowser: TWebBrowser;
begin
  WebBrowser := TWebBrowser.Create(Self);
  TWinControl(WebBrowser).Parent := Self;
  (WebBrowser as TWinControl).Parent := Self; // fail here
end

Parent in TWebBrowser is a read-only IDispatch property, but why does the first cast see the TWinControl parent property ok but the second one does not?

Thanks

Answers


The first cast use no checking, it assumes the programmer is right and goes on. The second cast uses some sanity checking. (Causes an exception if the cast is invalid). I think in this case, the compiler got confused because of the like named properties. It could even be an overenthousiastic optimizer.

At least,

var
  wc : TWinControl;
begin
  wc := (WebBrowser as TWinControl);
  wc.Parent := Self;
end;

Works. So there is a circumvention.


Need Your Help

Can I “pass” an object with a JSF param tag?

java jsf httpwebrequest

What I'm looking for is to have an f:param tag with an Object of my own choosing in the value attribute. Then, in the backing bean method for the action, I would like to be able to pull this Object...

VB.Net MVC4 Advanced entity creation on form submit w/jQuery

jquery asp.net-mvc entity-framework asp.net-mvc-4

I have a form which is submitting a collection of TimeItems (a table object), which are then going to be added to the database. The problem I am encountering is that I want to allow the user to add...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.