uses
Mshtml;
function CreateDocument(
const markup:
string): IHTMLDocument2;
var
doc: OleVariant;
begin
Result := CoHTMLDocument.Create
as IHTMLDocument2;
doc := Result;
doc.Open;
doc.
Write(markup);
doc.Close;
end;
procedure ShowIt(doc: IHTMLDocument2; s: TStrings);
const
MARKER = '
showit(';
var
i, iLeft, iRight: Integer;
ec: IHTMLElementCollection;
e: IHTMLElement;
value:
string;
begin
ec := doc.all.tags('
a')
as IHTMLElementCollection;
for i := 0
to Pred(
ec.length)
do
begin
e :=
ec.item(i, null)
as IHTMLElement;
value := e.getAttribute('
onclick', 0);
iLeft := Pos(marker, Lowercase(value)) + Length(marker);
iRight := LastDelimiter('
)', value);
if iLeft > Length(marker)
then value := Copy(value, iLeft, iRight- iLeft)
else value := '
';
s.QuoteChar := '
''
';
s.DelimitedText := value;
end;
end;
procedure TDemoForm.ButtonClick(Sender: TObject);
var
doc: IHTMLDocument2;
markup: TStrings;
begin
markup := TStringList.Create;
try
markup.LoadFromFile(ParamStr(1));
// oder LoadFromStream
doc := CreateDocument(markup.Text);
ShowIt(doc, markup);
ShowMessage(markup.Text);
finally
markup.Free;
end;
end;