No wlasnie szukalem tylko nic nie dziala, mialem to tak
uses mshtml
function GetFormByNumber(document: IHTMLDocument2;
formNumber: integer): IHTMLFormElement;
var
forms: IHTMLElementCollection;
begin
forms := document.Forms as IHTMLElementCollection;
if formNumber < forms.Length then
result := forms.Item(formNumber,'') as IHTMLFormElement
else
result := nil;
end;
procedure SetFieldValue(theForm: IHTMLFormElement;
const fieldName: string; const newValue: string);
var
field: IHTMLElement;
inputField: IHTMLInputElement;
selectField: IHTMLSelectElement;
textField: IHTMLTextAreaElement;
begin
field := theForm.Item(fieldName,'') as IHTMLElement;
if Assigned(field) then
begin
if field.tagName = 'textarea' then
begin
textField := field as IHTMLTextAreaElement;
textField.value := newValue;
end;
end;
end;
document := WebBrowser1.Document as IHTMLDocument2;
firstForm := GetFormByNumber(document,0);
theForm := GetFormByNumber(WebBrowser1.Document as IHTMLDocument2,0);
SetFieldValue(firstForm,'com_txt','asdfasd');
to nie dziala niewiem dlaczego
a jak daje takie cos
function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;
//no form on document
if form1.WebBrowser1.OleObject.Document.all.tags('FORM').Length = 0 then
begin
Showmessage('nera formu');
Exit;
end;
//count forms on document
for I := 0 to Form1.WebBrowser1.OleObject.Document.forms.Length - 1 do
begin
form1.memo1.lines.add(WebBrowser.OleObject.Document.forms.Length - 1);
FormItem := Form1.WebBrowser1.OleObject.Document.forms.Item(I);
form1.memo1.lines.add(FormItem);
for j := 0 to FormItem.Length - 1 do
begin
try
//when the fieldname is found, try to fill out
if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
ShowMessage('ajajai klaida');
Exit;
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
document: IHTMLDocument2;
firstForm: IHTMLFormElement;
theForm: IHTMLFormElement;
begin
FillForm(Form1.WebBrowser1, 'com_txt', 'asdfasd')
end;
to wyswietla nera forum czyli ze nie znalejziono formulaza :/