[Delphi] Parse a Memo.caption for urls

How could I parse a memo.caption for every URL?
kthxbai2uAsked:
Who is Participating?
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
Hmmm, doesn't  that post have an answer posted by ME?
What I posted was essentially the same code.
0
 
Geert GOracle dbaCommented:
a memo doesn't have a caption

don't you mean the contents of the memo ?
memo.lines ?
0
 
kthxbai2uAuthor Commented:
No. I mean exactly what I said. I have a TMemo filled with HTML. Now I want to extract ALL of the URL's from the HREF tags inside the contents of that memo.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kthxbai2uAuthor Commented:
Oh, i said caption by mistake haha... I must have just been working with a label :-/ It is a TMemo though.
0
 
Geert GConnect With a Mentor Oracle dbaCommented:
a tag is usually designated as <A HREF="xxx">yyy</A>
Do you want the yyy or the "xxx" ?

this parses out the yyy
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23867345.html#a22863486
0
 
Eddie ShipmanAll-around developerCommented:
I believe this will do the trick for you. It takes the HTML in Memo1.Text and parses it for all the <A> tags
and places them in Strl stringList and them assigns them to Memo2.

procedure TForm1.Button1Click(Sender: TObject);
var
  IDoc:    IHTMLDocument2;
  Strl:    TStringList;
  strHTML: String;
  v:       Variant;
  Links:   IHTMLElementCollection;
  i:       Integer;
  Link:    IHTMLAnchorElement;
begin
  strHTML := Meno1.Text;
  Strl := TStringList.Create;
  try
    Idoc:=CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
    try
      IDoc.designMode:='on';
      while IDoc.readyState<>'complete' do
        Application.ProcessMessages;
      v:=VarArrayCreate([0,0],VarVariant);
      v[0]:= strHTML;
      IDoc.write(PSafeArray(System.TVarData(v).VArray));
      IDoc.designMode:='off';
      while IDoc.readyState<>'complete' do
        Application.ProcessMessages;
      for i := 0 to IDoc.all.length - 1 do
      begin
        if Supports(IDoc.all.item(i, 0), IHTMLAnchorElement, Link) then
        begin
          Strl.Add(Copy(Link.href);
        end;
      end;
    finally
      IDoc := nil;
    end;
  finally
    // Strl contains all the links with .txt
    Memo2.Lines.Assign(Strl);
    Strl.Free;
  end;
end;

Open in new window

0
 
Eddie ShipmanAll-around developerCommented:
Make sure you use MSHTML in the uses.
0
 
kthxbai2uAuthor Commented:
EddieShipman:

Although this is EXACTLY what I want to do, it doesn't work in D2009.

it complains of undeclared identifier (underlines Application.ProcessMessages)
and also complains the same thing about the createComObject() call

Geert Gruwez:

Those might work, in D6-8, but I cant find a single component that I can use freely without trial. I installed one and it didn't even show on the component list.


Everyone:

I would prefer just a simple function, because I can just copy/paste and make minimal modifications... Although if the component is tested and working on D2009 I will accept that as well :)
0
 
kthxbai2uAuthor Commented:
psafearray() gives the same error...

are there any other uses other than MSHTML ?
0
 
kthxbai2uAuthor Commented:
Geert:

I also meant to mention I want the 'xxx' out of the link in your example
0
 
kthxbai2uAuthor Commented:
0
 
Eddie ShipmanAll-around developerCommented:
Application.ProcessMessages is defined in Forms.pas, is it in your uses?
CreateComObject is defined in ComObj, is it in your uses?
0
 
kthxbai2uAuthor Commented:
Well,

Ignoring the fact that you posted the answer in that one, I would still give you the points for getting me the closest to my answer...

Therefore, I will give you the points. Thanks for posting here to clear that up, because I was trying to assign the points to myself haha
0
 
Eddie ShipmanAll-around developerCommented:
Were you getting relative URLs (about:page.html) or absolute URLS (mysite.com/page.html)?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.