Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding images from the internet to a form 1

Status
Not open for further replies.

bill2727

Programmer
Apr 22, 2004
5
US
I can only find a way to insert static, local copies of an image into a form. What I'm trying to do is insert an image from a URL into my project, so that it can change even after the project is compiled. Is this possible?
Thanks for any help,
Bill
 
Not sure if this is the best way to do it but...

1) Place a TWebBrowser component on your form - this can act as your image container.

2) Place a TTimer on your form and set its Interval property to say 10000.

3) In the TTimer's OnTimer event place the following code, substituting for your URL:
Code:
WebBrowser1.Navigate('[URL unfurl="true"]http://www.blah.co.uk/Image.jpg');[/URL]

Hope this helps!

Clive [infinity]
 
That does work, but in only displaying a picture I'm worried it'll be too slow, or the scroll bars or border will show up and make it look ugly.
Thanks though- I'll find out soon whether this solution is workable or not.
 
Yeah, I can't seem to get rid of the vertical scroll bar, even though its grayed out. I don't see any properties of the webbrowser that fixes this. Is there a way to remove it?
 
I did a quick search on google for: delphi twebbrowser scrollbar. It brought up the following link:

So, all you need to do is this:
1) In the WebBrowser's OnDocumentComplete event put the following code:
Code:
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  {turn off scrollbars}
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
    Application.ProcessMessages;
  WebBrowser1.OleObject.document.body.style.overflowX := 'hidden';
  WebBrowser1.OleObject.document.body.style.overflowY := 'hidden';
end;

As far as I can make out, there are further properties available (but kind of hidden) in the OleObject property, which is an embedded ActiveX control.

Clive [infinity]
 
I can't seem to get that function to remove scrollbars to work. It says "Undeclared identifier WebBrowser1onDocumentComplete". I also can't access any properties of my TWebBrowser. Am I missing something?
 
What is your TWebBrowser component named? The best way to get this working is to delete last function i gave you, go to the Object Inspector for the TWebBrowser component, click the Events tab and double-click in the whitespace next to OnDocumentComplete. This should create an empty event in which you can place the code:
Code:
  {turn off scrollbars}
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do
    Application.ProcessMessages;
  WebBrowser1.OleObject.document.body.style.overflowX := 'hidden';
  WebBrowser1.OleObject.document.body.style.overflowY := 'hidden';

Clive [infinity]
 
Hey, it worked! As you can see I'm not very facile with delphi, I've just been given the job of editing the source code of a delphi project.
The resulting code seemed identical, but for whatever reason clicking on the event tab and inserting the code worked.
Thanks,
Bill
 
The reason was that your TWebBrowser was probably given a different name (mine was called WebBrowser1) or your form was called something different (mine was called Form1), so Delphi did not recognise the procedure name. An event's structure is as follows:
Code:
procedure FormName.ComponentNameEventName(..);
where EventName has the 'On' prefix removed. So for a TButton OnClick event for button3 in Form2 the event header (which you can automatically generate from the Object Inspector) would be:
Code:
procedure Form2.button3Click(..);

Hope this helps!


Clive [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top