Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi EIntfCastError??? (https://www.delphipraxis.net/87395-eintfcasterror.html)

MuTzE 28. Feb 2007 04:03


EIntfCastError???
 
Hallo,

ich möchte in meinem Programm folgenden Code verwenden, um die Items eines DropDown Menüs zu ermitteln und zu setzen.
Ich habe ihn hier gefunden: ...Listbox Items eines TWebBrowser Documents auflisten?


Delphi-Quellcode:

uses
  MSHTML;

function IsSelectElement(eleElement: IHTMLElement): Boolean;
var
  selElement: IHTMLSelectElement;
begin
  Result := False;
  try
    selElement := eleElement as IHTMLSelectElement;
  except
    Exit;
  end;
  Result := True;
end;

procedure GetListBoxOptions(Web1: TWebBrowser;
  strListBoxName: string;
  intInstance: Integer;
  tslLines: TStrings;
  out intSelected: Integer);
var
  eleChild: IHTMLElement;
  eleElement: IHTMLElement;
  colGrandParents: IHTMLElementCollection;
  colParents: IHTMLElementCollection;
  selElement: IHTMLSelectElement;
  intCount: Integer;
  intG: Integer;
  intGMax: Integer;
  intP: Integer;
  intPMax: Integer;
  Document: IHTMLDocument2;
begin
  tslLines.Clear;
  intSelected := -1;
  intCount   := -1;

  Document := Web1.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;

   // Hier kommt der Fehler
    if IsSelectElement(eleElement) then

    begin
      selElement := eleElement as IHTMLSelectElement;
      if selElement.Name = strListBoxName then
      begin
        Inc(intCount);
        if intCount = intInstance then
        begin
          intSelected := selElement.selectedIndex;
          colParents := eleElement.children as IHTMLElementCollection;
          intPMax := colParents.Length - 1;
          for intP := 0 to intPMax do
          begin
            eleChild := colParents.Item(intP, '') as IHTMLElement;
            tslLines.Add(eleChild.InnerText);
          end;
        end;
      end;
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 WebBrowser1.Navigate('http://www.swissdelphicenter.ch/torry');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  intSelected: Integer;
begin
  ComboBox1.Text := '';
  GetListBoxOptions(WebBrowser1, 'select', 0, ComboBox1.Items, intSelected);
  if intSelected > -1 then
  begin
    ComboBox1.Text := ComboBox1.Items[intSelected];
  end;
end;

An der oben, im Source bezeichneten Stelle kommt der Fehler: "EIntfCastError: Schnittstelle nicht unterstützt"


Ich hab keine Ahnung was das bedeutet bzw. wie ich das Problem löse. Kann mir jemand helfen?



MfG

MuTzE

MuTzE 28. Feb 2007 05:05

Re: EIntfCastError???
 
Hat sich erledigt, habe eine andere Variante gefunden!

Luckie 28. Feb 2007 06:30

Re: EIntfCastError???
 
Wäre nett, wenn du auch deine Lösung hier veröffentlichen würdest. Danke.

MuTzE 1. Mär 2007 20:53

Re: EIntfCastError???
 
Reading & Writing Form Elements


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz