Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.06.11;
Скачать: [xml.tar.bz2];

Вниз

EAccessViolation и IHTMLLinkElement   Найти похожие ветки 

 
mfender ©   (2006-05-24 16:19) [0]


var
 Links: IHTMLElementCollection;
 Link: IHTMLLinkElement;
....
 for i := 0 to Links.length - 1 do
 begin
   Link := IHTMLLinkElement(Links.item(i, EmptyParam));
   Memo1.Lines.Add(Link.href);
 end;


Ругается в строке "Memo1.Lines.Add(Link.href);" - EAccessViolation. В чём дело - не пойму...


 
Elen ©   (2006-05-24 16:26) [1]

Link.href какой тип имеет?


 
mfender ©   (2006-05-24 16:27) [2]

Elen ©   (24.05.06 16:26) [1]
Link.href какой тип имеет?

Вот в том-то и беда - WideString. Видимо на это и ругается. А что сним делать - не знаю. Уже весь INet перерыл - ничего не вижу по этому вопросу...


 
wal ©   (2006-05-24 16:31) [3]

А ты уверен, что Link получил? Рекомендую проверить на nil


 
mfender ©   (2006-05-24 16:35) [4]

wal ©   (24.05.06 16:31) [3]
А ты уверен, что Link получил? Рекомендую проверить на nil

А что там можно ещё получить? 8/


 
Elen ©   (2006-05-24 16:36) [5]

Поставь точку прерывания на этом операторе и посмотри чему равен link. Такое подозрение что он равен nil в каких-то моментах
Или попробуй что нибудь вроде :
for i := 0 to Links.length - 1 do
begin
 Link := IHTMLLinkElement(Links.item(i, EmptyParam));
 if link<> nil then Memo1.Lines.Add(Link.href) else {Другие действия}
end;


 
wal ©   (2006-05-24 16:38) [6]


> А что там можно ещё получить? 8/
тот же nil


 
mfender ©   (2006-05-24 16:47) [7]

Elen ©   (24.05.06 16:36) [5]
Поставь точку прерывания на этом операторе и посмотри чему равен link. Такое подозрение что он равен nil в каких-то моментах
Или попробуй что нибудь вроде :
for i := 0 to Links.length - 1 do
begin
Link := IHTMLLinkElement(Links.item(i, EmptyParam));
if link<> nil then Memo1.Lines.Add(Link.href) else {Другие действия}
end;


Попробовад так - результат тот же. Что характерно, showmessage(IntToStr(Links.length)); показывает 60. И сделал:


   try
     Memo1.Lines.Add(Link.href);
   except
     Memo1.Lines.Add("error");
   end;


пишет "error" в количестве шестидесяти штук. :(


 
Elen ©   (2006-05-24 17:04) [8]

У тебя где-то проскакивает nil проверь Links.length - 1 чему равен?
И поставь точку прерывания на Memo1.Lines.Add(Link.href)
и смотри все переменки когда она сработает


 
saxon   (2006-05-24 17:06) [9]

IHTMLAnchorElement
document-anchors(коллекция элементов anchor)
IHTMLLinkElement - для тега <LINK> используется


 
saxon   (2006-05-24 17:12) [10]

Я правильно понял?


 
Плохиш ©   (2006-05-24 17:31) [11]


> mfender ©   (24.05.06 16:19)

Я не знаю, что скрывается за Вашими "....". Но рекомендую сделать проверку на то, что полученный item действительно является ссылкой. См. пример для ListBox в http://www.swissdelphicenter.ch/de/showcode.php?id=2357


 
mfender ©   (2006-05-24 17:52) [12]

saxon   (24.05.06 17:06) [9]
IHTMLAnchorElement
document-anchors(коллекция элементов anchor)
IHTMLLinkElement - для тега <LINK> используется


Действительно...
Но даже с IHTMLAnchorElement результат остался тот же...


 
mfender ©   (2006-05-24 17:54) [13]

Дебугер пишет, что Link - Pointer($<много цифер>), Link.href - AccessViolation... Странно всё это... Links.length - 60.


 
Плохиш ©   (2006-05-24 17:58) [14]

Следующий код выводит список всех тэгов на странице

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, OleCtrls, SHDocVw, StdCtrls, ExtCtrls, MSHTML;

type
 TForm1 = class(TForm)
   WebBrowser1: TWebBrowser;
   Memo1: TMemo;
   Panel1: TPanel;
   Edit1: TEdit;
   Button1: TButton;
   Button2: TButton;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
 private
   { Private-Deklarationen }
   procedure ViewTags;
 public
   { Public-Deklarationen }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 WebBrowser1.Navigate(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Memo1.Clear;
 ViewTags;
end;

procedure TForm1.ViewTags;
var
 eleElement: IHTMLElement;
 colGrandParents: IHTMLElementCollection;
 intG: Integer;
 intGMax: Integer;
 Document: IHTMLDocument2;
begin
 Document := WebBrowser1.Document as IHTMLDocument2;
 if Document = nil then Exit;

 colGrandParents := Document.All;
 if colGrandParents = nil then Exit;

 intGMax := colGrandParents.Length - 1;
 for intG := 0 to intGMax do
 begin
   eleElement := colGrandParents.Item(intG, "") as IHTMLElement;
   Memo1.Lines.Add(eleElement.className + " - " + eleElement.id + " - " + eleElement.tagName + " = ");
 end;
end;

end.


 
Плохиш ©   (2006-05-24 18:05) [15]

А вот подправленная функция, выводящая только ссылки из тэгов LINK

procedure TForm1.ViewTags;
var
 eleElement: IHTMLLinkElement; //IHTMLElement;
 colGrandParents: IHTMLElementCollection;
 intG: Integer;
 intGMax: Integer;
 Document: IHTMLDocument2;
begin
 Document := WebBrowser1.Document as IHTMLDocument2;
 if Document = nil then Exit;

 colGrandParents := Document.All;
 if colGrandParents = nil then Exit;

 intGMax := colGrandParents.Length - 1;
 for intG := 0 to intGMax do
 try
   eleElement := colGrandParents.Item(intG, "") as IHTMLLinkElement;  //IHTMLElement;
   Memo1.Lines.Add(eleElement.type_ + " = " + eleElement.href);
//    Memo1.Lines.Add(eleElement.className + " - " + eleElement.id + " - " + eleElement.tagName + " = ");
 except
 end;
end;


 
saxon   (2006-05-24 18:08) [16]

Как ты берешь Links, Document.Links или Document.Anchors?


 
mfender ©   (2006-05-24 18:15) [17]


procedure TForm1.Button1Click(Sender: TObject);
var
 Links: IHTMLElementCollection;
 Link: IHTMLImgElement;
 i: Integer;
begin
 Memo1.Clear;
 Links := IDoc.images;
 showmessage(IntToStr(Links.length));
 for i := 0 to Links.length - 1 do
 begin
   Link := IHTMLImgElement(Links.item(i, EmptyParam));
   try
     Memo1.Lines.Add(Link.src);
   except
     Memo1.Lines.Add("error");
   end;
 end;
end;


IDoc, соответственно - IHTMLDocument2.


 
Плохиш ©   (2006-05-24 18:23) [18]

Пожалуйста для img

procedure TForm1.ViewTags;
var
 eleElement: IHTMLImgElement;
 colGrandParents: IHTMLElementCollection;
 intG: Integer;
 intGMax: Integer;
 Document: IHTMLDocument2;
begin
 Document := WebBrowser1.Document as IHTMLDocument2;
 if Document = nil then Exit;

 colGrandParents := Document.images;
 if colGrandParents = nil then Exit;

 intGMax := colGrandParents.Length - 1;
 Label1.Caption := IntToStr(intGMax+1);
 for intG := 0 to intGMax do
 try
   eleElement := colGrandParents.Item(intG, "") as IHTMLImgElement;
   Memo1.Lines.Add(eleElement.src + " = " + eleElement.href);
 except
 end;
end;


 
mfender ©   (2006-05-24 18:51) [19]

Вобщем, понятно. Спасибо всем!

И последний вопрос, по существу вопроса: всё шило крылось в строке IHTMLAnchorElement(Links.item(i, "")); И всё заработало, когда написал Links.item(i, "") as IHTMLAnchorElement; До сих пор я, видимо наивно, полагал, что это - одно и то же. Разве не так?


 
Плохиш ©   (2006-05-24 19:18) [20]


> Разве не так?

Нет

> IHTMLAnchorElement(Links.item(i, ""));

это обычное приведение типов

> Links.item(i, "") as IHTMLAnchorElement;

а в этом случае производится проверка на соответствие и в случае не совпадения типов будет поднято исключение.


 
mfender ©   (2006-05-24 22:19) [21]

Плохиш ©   (24.05.06 19:18) [20]
Спасибо, буду знать теперь.



Страницы: 1 вся ветка

Форум: "Начинающим";
Текущий архив: 2006.06.11;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.51 MB
Время: 0.012 c
4-1142584324
Turbid
2006-03-17 11:32
2006.06.11
Колесико над иконкой в трее


11-1128113989
TamTam
2005-10-01 00:59
2006.06.11
Цвет и вид шрифта


2-1148210008
NiGGa
2006-05-21 15:13
2006.06.11
инет.


15-1147899614
fantom423
2006-05-18 01:00
2006.06.11
У кого есть красивые компоненты под базу даных?!!


2-1148245086
Adolf
2006-05-22 00:58
2006.06.11
Срочно нужна помощь!





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский