2
I need to set the value of a field Select of a page that is loaded into the Twebbrowser component in Delphi 7. This procedure I can do in other fields where values are equal to the options texts, but in another field as are hundreds of values and the text of the option Select is different from the value, so I can’t. The Procedure I need is like this below:
function SelectOptionByValue(const ADocument: IDispatch; const AElementID,
AOptionValue: WideString): Integer;
var
HTMLDocument: IHTMLDocument3;
HTMLElement: IHTMLSelectElement;
function IndexOfValue(const AHTMLElement: IHTMLSelectElement;
const AValue: WideString): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to AHTMLElement.length - 1 do
if (AHTMLElement.item(I, I) as IHTMLOptionElement).value = AValue then
begin
Result := I;
Break;
end;
end;
begin
Result := -1;
if Supports(ADocument, IID_IHTMLDocument3, HTMLDocument) then
begin
if Supports(HTMLDocument.getElementById(AElementID), IID_IHTMLSelectElement,
HTMLElement) then
begin
Result := IndexOfValue(HTMLElement, AOptionValue);
HTMLElement.selectedIndex := Result;
end;
end;
end;
Procedure above only serves when the text of the field option Select is equal to the option value. For example:
SelectOptionByValue(web.Document, 'fNaturalidade', DMCadastros.cdsClientesUF.AsString);
Yes, sorry.
– Carlos Andrade