Einzelnen Beitrag anzeigen

Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#6

AW: Webbrowser (Tembbeded) - Unültige Variantenoperation

  Alt 21. Mär 2013, 17:59
Hier kommt etwas Code, mit dem du alle Form-Objekte im Browser in einem TreeView anzeigen kannst.
Das ist recht hilfreich bei der Fehlersuche und um die API des Webbrowsers besser zu verstehen:
Delphi-Quellcode:
procedure Browser2TreeView(WebBrowser: TWebBrowser; root:TTreeNodes);
var
  i,j, k :Integer;
  FormItem, Element, SubElement: OleVariant;
  child, child2, child3 : TTreeNode;
  s_type : string;
begin
   Assert(Assigned(WebBrowser));
   Assert(Assigned(root));

   root.Clear;

  //count forms on document
  for I:=0 to WebBrowser.OleObject.Document.forms.Length -1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);

    if VariantIsObject(FormItem.Name) then
       child := root.AddChild(nil, 'Form'+IntToStr(i)+': '+FormItem.Name.Name)
    else
       child := root.AddChild(nil, 'Form'+IntToStr(i)+': '+FormItem.Name);
    child.ImageIndex := 3;


    For j:= 0 to FormItem.Length-1 do
    begin
      try
         Element := FormItem.Item(j);
         child2 := root.AddChild(child, Element.Name+' = '+Element.Value);
         s_type := Element.Type;

         if s_type = 'submitthen
            child2.ImageIndex := 1
         else if s_type = 'textthen
            child2.ImageIndex := 0
         else if s_type = 'filethen
            child2.ImageIndex := 2
         else if s_type = 'hiddenthen
            child2.ImageIndex := 4
         else if s_type = 'checkboxthen
            child2.ImageIndex := 5
         else if s_type = 'radiothen
            child2.ImageIndex := 6
         else if s_type = 'select-onethen
            child2.ImageIndex := 7
         else
            child2.ImageIndex := -1;

         child3 := root.AddChild(child2, 'Type='+s_type);
         child3.ImageIndex := -1;


         if s_type = 'textthen
         begin
            child3 := root.AddChild(child2, 'MaxLen='+IntToStr(Element.maxLength));
            child3.ImageIndex := -1;
         end
         else if s_type = 'select-onethen
         begin
            for k := 0 to Element.Options.Length-1 do
            begin
               SubElement := Element.Options.Item(k);
               child3 := root.AddChild(child2, SubElement.Text+ ' = <'+SubElement.Value+'>');
               child3.ImageIndex := -1;
            end;

         end;

      except
        on E:Exception do
         root.AddChild(child, E.Message);
      end;
    end;
  end;

   if root.Count > 0 then
      root.GetFirstNode.Expand(True);
end;
Der Aufruf dazu sieht so aus: Browser2TreeView(WebBrowser1, TreeView1.Items); Dem Treeview sollte eine Imagelist mit 8 Bildchen der Grösse 16 * 16 zugeordnet werden.
Du kannst den Code im Anhang in dein Clipboard kopieren und dann das Formular anklicken und in der IDE Bearbeiten->Einfügen wählen.
Angehängte Dateien
Dateityp: txt imagelist.txt (27,5 KB, 7x aufgerufen)

Geändert von sx2008 (21. Mär 2013 um 18:04 Uhr)
  Mit Zitat antworten Zitat