Advanced Hyperlink Labels
Hi..
Anyone know a good solution for creating "real-world" hyperlinks in a PDF
document? I am using TExtraDevices, but it only recognizes a text object as
a URL when its text property is something like http://www.mydomain.com, but
I would rather the PDF say something like "Click Here".
So I have an idea. I added some code to a labels OnGetText event and that
labels caption property set to the following:
textlink("Click Here","http://www.mydomain.com")
This text is parsed by the GetText event and a new label is created to have
a caption of the URL, which becomes clickable in the PDF). And the original
label is set to the visible portion of the text (Click Here)- and that
portion does work. The problem is the newly created label never shows in
the report. My guess is the report is already past the printing of that
label or the label is not actually processed. Anyone have any ideas how to
make the dynamically created label show?
My code for this:
procedure TForm1.ppLabel4GetText(Sender: TObject; var Text: String);
var
LinkParams: TStringList;
CommaText: String;
ppLinkLabel: TppLabel;
begin
If POS( 'textlink(', Text) = 1 then
Begin
LinkParams := TStringList.Create;
ppLinkLabel := TppLabel.Create(TppLabel(Sender));
try
CommaText := Text;
Delete(CommaText, 1, 9);
Delete(CommaText, Length(CommaText), 1);
LinkParams.CommaText := CommaText;
Text := LinkParams.Strings[0];
//ShowMessage( LinkParams.Strings[1]);
ppLinkLabel.Name := TppLabel(Sender).Name + 'URL';
ppLinkLabel.Caption := LinkParams.Strings[1];
ppLinkLabel.AutoSize := False;
ppLinkLabel.Left := TppLabel(Sender).Left;
ppLinkLabel.Top := TppLabel(Sender).Top;
ppLinkLabel.Width := TppLabel(Sender).Width;
ppLinkLabel.Height := TppLabel(Sender).Height;
ppLinkLabel.Visible := True;
ppLinkLabel.UserName := 'Label5457';
// set font of new label to white so the underlying URL is not
visible.
finally
LinkParams.Free;
end;
end;
end;
Thanks in advance,
Tom
tom @ comvantage dot com
Anyone know a good solution for creating "real-world" hyperlinks in a PDF
document? I am using TExtraDevices, but it only recognizes a text object as
a URL when its text property is something like http://www.mydomain.com, but
I would rather the PDF say something like "Click Here".
So I have an idea. I added some code to a labels OnGetText event and that
labels caption property set to the following:
textlink("Click Here","http://www.mydomain.com")
This text is parsed by the GetText event and a new label is created to have
a caption of the URL, which becomes clickable in the PDF). And the original
label is set to the visible portion of the text (Click Here)- and that
portion does work. The problem is the newly created label never shows in
the report. My guess is the report is already past the printing of that
label or the label is not actually processed. Anyone have any ideas how to
make the dynamically created label show?
My code for this:
procedure TForm1.ppLabel4GetText(Sender: TObject; var Text: String);
var
LinkParams: TStringList;
CommaText: String;
ppLinkLabel: TppLabel;
begin
If POS( 'textlink(', Text) = 1 then
Begin
LinkParams := TStringList.Create;
ppLinkLabel := TppLabel.Create(TppLabel(Sender));
try
CommaText := Text;
Delete(CommaText, 1, 9);
Delete(CommaText, Length(CommaText), 1);
LinkParams.CommaText := CommaText;
Text := LinkParams.Strings[0];
//ShowMessage( LinkParams.Strings[1]);
ppLinkLabel.Name := TppLabel(Sender).Name + 'URL';
ppLinkLabel.Caption := LinkParams.Strings[1];
ppLinkLabel.AutoSize := False;
ppLinkLabel.Left := TppLabel(Sender).Left;
ppLinkLabel.Top := TppLabel(Sender).Top;
ppLinkLabel.Width := TppLabel(Sender).Width;
ppLinkLabel.Height := TppLabel(Sender).Height;
ppLinkLabel.Visible := True;
ppLinkLabel.UserName := 'Label5457';
// set font of new label to white so the underlying URL is not
visible.
finally
LinkParams.Free;
end;
end;
end;
Thanks in advance,
Tom
tom @ comvantage dot com
This discussion has been closed.
Comments
Taking a look at your code, it does not look like you are actually adding
the link label to the report. To do this you need to assign it's Band
property.
lLabel := TppLabel.Create(Self);
lLabel.Band := Report.TitleBand;
lLabel.Caption := 'My Label';
... etc.
I'm also unsure the OnGetText event fires early enough to actually add a new
text component to a report. If you are still experiencing issues, you might
try using the Band.BeforePrint or earlier events and see if that gives you
better success.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The band property makes sense. I was thinking it was parent like you would
expect in Delphi forms. However, the new field still did not show. I tried
it on Band.BeforePrint and Report.BeforePrint (the Report.BeforePrint event
never fired though) as well. I also tried BeforeSecondPass, but that didn't
work either- appeared to be too late (the text was already processed).
Please keep in mind I am using a TppLabel, but I may use a database label as
well, so hopefully the proper event can handle this as well timing-wise.
Let me know what you find. Or if there is some other way to acheive the
same thing.
Thanks again,
Tom
It seems the band events all fire too late to actually add a report
component to the report in code. In my quick testing, it seemed to work
using the Report.BeforePrint event. Below is the code I used...
procedure TForm1.ppReport1BeforePrint(Sender: TObject);
var
lLabel: TppLabel;
begin
lLabel := TppLabel.Create(self);
lLabel.Band := ppReport1.DetailBand;
lLabel.Left := 0;
lLabel.Top := 0;
lLabel.AutoSize := True;
lLabel.Font.Size := 24;
lLabel.Font.Color := clBlue;
lLabel.Caption := 'Dynamic Label';
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com