Search code examples
delphiinternet-explorerdelphi-xetembeddedwb

Delphi XE - read style property of HTML objects


I am using the class TEmbeddedWB to Access HTML elements in an embedded Web Browser in a Delphi program.

After much googling I can't come up with a solution for the following issue: How to directly read style properties of objects?

I tried:

Event.srcElement.getAttribute('style', 0)

and it returns (in CodeSite Live Viewer) [object MSStyleCSSProperties]

 Event.srcElement.getAttribute('style.display', 0)

returns an empty string (but in the code it is defined as block). I guess, this ominous object can be accessed some way to read the declared (or computed?) CSS properties; but I can't figure out how it can be achieved. To what type of variable should I assign the return value of getAttribute('style', 0)? Will the result be as declared or as computed?

There is no type MSStyleCSSProperties declared.

Any help would be appreciated.

I am a Delphi beginner. Sorry if this question is nooby.


Solution

  • The IHTMLElement has a property named style which is a IHTMLStyle object, and that object has some useful methods and properties that can help you.

    Check this out:

    Tag:IHTMLElement; // <div style="display: none;">
    
    Memo1.Lines.Add(Tag.style.cssText); //Outputs "display: none;"
    Memo1.Lines.Add(Tag.style.display); //Outputs "none"