?
Solved

[Delphi] Parse a Memo.caption for urls

Posted on 2009-04-28
15
Medium Priority
?
467 Views
Last Modified: 2012-05-06
How could I parse a memo.caption for every URL?
0
Comment
Question by:kthxbai2u
  • 7
  • 5
  • 3
15 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24258135
a memo doesn't have a caption

don't you mean the contents of the memo ?
memo.lines ?
0
 

Author Comment

by:kthxbai2u
ID: 24262469
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
 

Author Comment

by:kthxbai2u
ID: 24262477
Oh, i said caption by mistake haha... I must have just been working with a label :-/ It is a TMemo though.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 150 total points
ID: 24263425
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
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 150 total points
ID: 24263447
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 24263559
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
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 24263562
Make sure you use MSHTML in the uses.
0
 

Author Comment

by:kthxbai2u
ID: 24264158
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
 

Author Comment

by:kthxbai2u
ID: 24264171
psafearray() gives the same error...

are there any other uses other than MSHTML ?
0
 

Author Comment

by:kthxbai2u
ID: 24264205
Geert:

I also meant to mention I want the 'xxx' out of the link in your example
0
 

Author Comment

by:kthxbai2u
ID: 24264369
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 24264485
Application.ProcessMessages is defined in Forms.pas, is it in your uses?
CreateComObject is defined in ComObj, is it in your uses?
0
 
LVL 26

Accepted Solution

by:
Eddie Shipman earned 1350 total points
ID: 24264505
Hmmm, doesn't  that post have an answer posted by ME?
What I posted was essentially the same code.
0
 

Author Comment

by:kthxbai2u
ID: 24264587
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
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 24264658
Were you getting relative URLs (about:page.html) or absolute URLS (mysite.com/page.html)?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question