BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trying to get CSS StyleSheet rules but... I get E_ACCESSDENI

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet
View previous topic :: View next topic  
Author Message
danieldc
Guest





PostPosted: Tue Aug 01, 2006 11:35 pm    Post subject: Trying to get CSS StyleSheet rules but... I get E_ACCESSDENI Reply with quote



The code below receives a HTML Document 2 interface and extract a list
of all CSS selectors and attributes from tags LINK type="text/css"
rel="stylesheet".

I noticed that when the document (HTML file) is a simple one, that's,
it begins with the HTML tag, has a HEADER and BODY, no problem, the
code get each style sheet and then each css rule.

But if the HTML document begins with some strange code, like comments
(<--! -->) or something really usual like "<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">", then all I can get is a
E_ACCESSDENIED ($80070005) when I try the ".rules" property of the
IHTMLStyleSheet object.


Please, help me!
What I'm doing wrong?

thanks, yours,
Daniel, from Brazil
- - - - - - - - - - - - - - - - - - - - - - - - -

procedure TformStyleSheet.doGetStyleSheets(doc:IHTMLDocument2);

var iSC:IHtmlStyleSheetsCollection;
iSS:IHtmlStyleSheet;
iRulesCol:IHtmlStyleSheetRulesCollection;
iSSRule:IHtmlStyleSheetRule;
iRuleStyle:IHtmlRuleStyle;
iDisp: IDispatch;

hr:HResult;
i,k:integer;
j:OleVariant;
s:ansistring;
b:boolean;

procedure doInit;
// only put an "nil" value at variables
begin
iSC:=nil;
iSS:=nil;
iRulesCol:=nil;
iSSRule:=nil;
iRuleStyle:=nil;
iDisp:=nil;
hr:=0;
end;


function doGetInterfaces:boolean;
// get the IHTMLStyleSheetsCollection object
var hr:HResult;
begin
result:=false;
// hr:=doc.QueryInterface(IID_IHTMLStyleSheetsCollection,iSC);
// queryinterface don't work... then, go to the property
iSC:=doc.styleSheets;
if
TestError(0,pointer(iSC),'IID_IHTMLStyleSheetsCollection','IHTMLDocument2')
then exit;
iSC._AddRef;
result:=true; //ok, "all" interfaces working!
end;

procedure doRelease;
// free/release objects
begin
if assigned(iSC) then iSC._Release;
// if assigned(iCS) then iCS._Release;
// if assigned(iHtml2) then iHtml2._Release;
end;

procedure addLT;
// show the style rule text...
begin
memo.lines.add(iSSRule.selectorText);
memo.lines.add(iRuleStyle.cssText);
end;



begin
doInit; // initialize variables
try
if doGetInterfaces then begin // get the object
IHTMLStyleSheetsCollection
for i:=1 to iSC.length do begin
j:=i-1;
iDisp:=iSC.item(j);
if assigned(iDisp) then begin
hr:=iDisp.QueryInterface(IID_IHTMLStyleSheet,iSS);
if
TestError(hr,pointer(iSS),'IID_IHTMLStyleSheet','IHTMLStyleSheetsCollection')
then begin
// impossible to get an single StyleSheet object, then
continue with next...
// exit;
end else begin
try
iSS._AddRef;

//hr:=iSS.QueryInterface(IID_IHTMLStyleSheetRulesCollection,iRulesCol);
//if hr<>0 then raise
Exception.Create(SysErrorMessage(hr));

//TestError(hr,pointer(iRulesCol),'IHTMLStyleSheetsCollection','IID_IHTMLStyleSheetRulesCollection');
// queryinterface don't work... let's try the
property...
try

iRulesCol:=iSS.rules;

// --> THE PROBLEM IS HERE!!! iSS.rules not alwalys can be accessed!
// Why? Some html documents works, but others... no way!
// A single line of html comment at beggining of html file can
trouble this all.

except
on e:Exception do
Showmessage('TformStyleSheet.doGetStyleSheets'#13+
'iRulesCol:=iSS.Rules
(failed)'#13#13+

'IHTMLStyleSheetsCollection('+inttostr(i-1)+')'#13+
'iSS.href =
'+iSS.href+#13+
'iSS.title =
'+iSS.title+#13#13+
e.message);

end;

if assigned(pointer(iRulesCol)) then begin
for k:=1 to iRulesCol.length do begin
try
iSSRule:=iRulesCol.item(k-1);

if
TestError(0,pointer(iSSRule),'IHTMLStyleSheetRule','IHTMLStyleSheetRulesCollection')
then begin
// nothing here
end else begin

hr:=iSSRule.QueryInterface(IID_IHTMLRuleStyle,iRuleStyle);
// queryinterface don't work... then, go to the
property
iRuleStyle:=iSSRule.style;
if
TestError(0,pointer(iRuleStyle),'IID_IHTMLRuleStyle','IHTMLStyleSheetRule')
then begin
// nothing here
end else begin
// do something with the css rule: show,
save, list and so on
addLT;
end;
end;
except
end;
end; // end for iRulesCol.length
end;
finally
iSS._Release;
end;
end;
end else begin
// ops! not a valid iDisp from iSC.item
end;
end;
end;
finally
doRelease;
end;
end;
Back to top
Riki Wiki
Guest





PostPosted: Wed Aug 02, 2006 12:40 am    Post subject: Re: Trying to get CSS StyleSheet rules but... I get E_ACCESS Reply with quote



On 1 Aug 2006 11:35:20 -0700, danieldc wrote:

Quote:
Please, help me!
What I'm doing wrong?

Hoi Daniel

You need to be aware that this news group do not officially exist. You need
to repost the question the newsgroup b.p.d.internet.winsock, and when you
do so you need to post on the Borland news server.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.