Im Anhang eine kleine
Unit zum Extrahieren von Links aus einer Textdatei:
Delphi-Quellcode:
type
TLinkObj = class(TObject)
public
RawLink: AnsiString;
HREF: AnsiString;
Caption: AnsiString;
end;
type
TOnRawLinkFound = procedure(Sender: TObject; Link: AnsiString) of object;
TOnCaptionFound = procedure(Sender: TObject; Caption: AnsiString) of object;
TOnHREFFound = procedure(Sender: TObject; HREF: AnsiString) of object;
TExtractLinksFromTextFile = class(TObject)
private
FFilename: AnsiString;
FLinkList: TObjectList;
FOnRawLinkFound: TOnRawLinkFound;
FOnCaptionFound: TOnCaptionFound;
FOnHREFFound: TOnHREFFound;
procedure GetRawLinks;
procedure GetHREF;
procedure GetCaption;
public
property Filename: AnsiString read FFilename write FFilename;
property LinkList: TObjectList read FLinkList;
property OnRawLinkFound: TOnRawLinkFound read FOnRawLinkFound write FOnRawLinkFound;
property OnCaptionFound: TOnCaptionFound read FOnCaptionFound write FOnCaptionFound;
property OnHREFFound: TOnHREFFound read FOnHREFFound write FOnHREFFound;
constructor Create;
destructor Destroy; override;
procedure ExtractLinks;
end;
Beispielcode:
Delphi-Quellcode:
procedure TForm14.Button1Click(Sender: TObject);
var
Links: TExtractLinksFromTextFile;
Link: TLinkObj;
i: Integer;
begin
Memo1.Clear;
Links := TExtractLinksFromTextFile.Create;
try
Links.OnRawLinkFound := OnRawLink;
Links.Filename := 'D:\Homepage\Admin\Bookmarks.shtml';
Links.ExtractLinks;
for i := 0 to Links.LinkList.Count - 1 do
begin
Link := TLinkObj(Links.LinkList.Items[i]);
Memo1.Lines.Add(Link.Caption+': '+ Link.HREF);
end;
finally
Links.Free;
end;
end;
procedure TForm14.OnRawLink(Sender: TObject; RawLink: AnsiString);
begin
ShowMessage(RawLink);
end;
Ein Teil meines Codes würde euch verunsichern.