S
softwind
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TBrowserForm.HtmlParser(TableName:String;ButtonName: WideString);
var
i: integer;
hr: HResult;
begin
ADOTable.TableName := TableName;
ADOTable.Open;
iDoc := WebBrowser1.Document as IHTMLDocument2 ;
iAll := iDoc.Get_all as IHTMLElementCollection;
iDisp := iAll.tags('INPUT');
iDisp.QueryInterface(IHTMLElementCollection, iElements);
iSelectDisp := iAll.tags('SELECT');
hr := iSelectDisp.QueryInterface(IHTMLElementCollection, iSelects);
if hr = S_OK then
begin
for i := 0 to iSelects.length - 1 do
begin
iSelect := iSelects.item(i, varEmpty) as IHTMLSelectElement;
SetSelectValue(iSelect,ADOTable);
end;
end;
for i := 0 to iElements.length - 1 do
begin
iInput := iElements.item(i, varEmpty) as IHTMLInputElement;
SetInputValue(iInput, ADOTable);
end;
for i := 0 to iElements.length - 1 do
begin
iInput := iElements.item(i, varEmpty) as IHTMLInputElement;
if Lowercase(iInput.type_) = 'button' then
begin
if iInput.name = Variant(ButtonName) then
begin
iBtn := iInput as iHTMLElement;
iBtn.Click;
break;
end;
end;
if Lowercase(iInput.type_) = 'submit'then
begin
if iInput.name = Variant(ButtonName) then
begin
iBtn := iInput as iHTMLElement;
iBtn.Click;
break;
end;
end;
end;
end;
procedure TBrowserForm.SetInputValue(iInput :IHTMLInputElement; Table: TADOTable);
var
I: Integer;
begin
if Lowercase(iInput.type_) = 'text' then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iInput.Name = Table.Fields.Fields.FieldName then
iInput.Value := Table.Fields.Fields.AsString;
end;
end; // for
if ( (Lowercase(iInput.type_) = 'radio') or (Lowercase(iInput.type_) = 'checkbox')) then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iInput.Name = Table.Fields.Fields.FieldName then
iInput.Value := Table.Fields.Fields.AsString;
end;
end; // for
end;
{---------------------------------------------------------------------------
设置Select的值
---------------------------------------------------------------------------}
procedure TBrowserForm.SetSelectValue(iSelect: IHTMLSelectElement; Table: TADOTable);
var
i: Integer;
begin
if Lowercase(iSelect.type_) = 'select-one' then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iSelect.name = Table.Fields.Fields.FieldName then
iSelect.value := Table.Fields.Fields.AsString;
end;
end;
end;
var
i: integer;
hr: HResult;
begin
ADOTable.TableName := TableName;
ADOTable.Open;
iDoc := WebBrowser1.Document as IHTMLDocument2 ;
iAll := iDoc.Get_all as IHTMLElementCollection;
iDisp := iAll.tags('INPUT');
iDisp.QueryInterface(IHTMLElementCollection, iElements);
iSelectDisp := iAll.tags('SELECT');
hr := iSelectDisp.QueryInterface(IHTMLElementCollection, iSelects);
if hr = S_OK then
begin
for i := 0 to iSelects.length - 1 do
begin
iSelect := iSelects.item(i, varEmpty) as IHTMLSelectElement;
SetSelectValue(iSelect,ADOTable);
end;
end;
for i := 0 to iElements.length - 1 do
begin
iInput := iElements.item(i, varEmpty) as IHTMLInputElement;
SetInputValue(iInput, ADOTable);
end;
for i := 0 to iElements.length - 1 do
begin
iInput := iElements.item(i, varEmpty) as IHTMLInputElement;
if Lowercase(iInput.type_) = 'button' then
begin
if iInput.name = Variant(ButtonName) then
begin
iBtn := iInput as iHTMLElement;
iBtn.Click;
break;
end;
end;
if Lowercase(iInput.type_) = 'submit'then
begin
if iInput.name = Variant(ButtonName) then
begin
iBtn := iInput as iHTMLElement;
iBtn.Click;
break;
end;
end;
end;
end;
procedure TBrowserForm.SetInputValue(iInput :IHTMLInputElement; Table: TADOTable);
var
I: Integer;
begin
if Lowercase(iInput.type_) = 'text' then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iInput.Name = Table.Fields.Fields.FieldName then
iInput.Value := Table.Fields.Fields.AsString;
end;
end; // for
if ( (Lowercase(iInput.type_) = 'radio') or (Lowercase(iInput.type_) = 'checkbox')) then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iInput.Name = Table.Fields.Fields.FieldName then
iInput.Value := Table.Fields.Fields.AsString;
end;
end; // for
end;
{---------------------------------------------------------------------------
设置Select的值
---------------------------------------------------------------------------}
procedure TBrowserForm.SetSelectValue(iSelect: IHTMLSelectElement; Table: TADOTable);
var
i: Integer;
begin
if Lowercase(iSelect.type_) = 'select-one' then
begin
for I := 0 to Table.FieldCount - 1 do // Iterate
begin
if iSelect.name = Table.Fields.Fields.FieldName then
iSelect.value := Table.Fields.Fields.AsString;
end;
end;
end;