TLama

Untitled

Jul 19th, 2013
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.22 KB | None | 0 0
  1. procedure SetFieldValue(FormElement: IHTMLFormElement; const FieldName, NewValue: WideString);
  2. var
  3.   I: Integer;
  4.   Element: IHTMLElement;
  5.   TextElement: IHTMLTextAreaElement;
  6.   InputElement: IHTMLInputElement;
  7.   SelectElement: IHTMLSelectElement;
  8. begin
  9.   Element := FormElement.item(FieldName, '') as IHTMLElement;
  10.   if Assigned(Element) then
  11.   begin
  12.     if Supports(Element, IID_IHTMLInputElement, InputElement) then
  13.     begin
  14.       // Make the change below to catch checks and radios.
  15.       if (InputElement.type_ = 'checkbox') or (InputElement.type_ = 'radio') then
  16.       begin
  17.         if newValue = 'Y' then
  18.           InputElement.checked := True
  19.         else
  20.           InputElement.checked := False;
  21.       end
  22.       else
  23.         InputElement.value := newValue;
  24.     end
  25.     else
  26.     if Supports(Element, IID_IHTMLSelectElement, SelectElement) then
  27.     begin
  28.       for I := 0 to SelectElement.length - 1 do
  29.         if (SelectElement.item(I, I) as IHTMLOptionElement).text = NewValue then
  30.         begin
  31.           SelectElement.selectedIndex := I;
  32.           Break;
  33.         end;
  34.     end
  35.     else
  36.     if Supports(Element, IID_IHTMLTextAreaElement, TextElement) then
  37.       TextElement.value := newValue;
  38.   end;
  39. end;
Advertisement
Add Comment
Please, Sign In to add comment