Solved

Download file to memory?

Posted on 2008-10-23
8
285 Views
Last Modified: 2013-11-23
Hi Experts,
Someone can help me to download a file (any file on webs) to the memory (stream or somthing)?

thanks :)
0
Comment
Question by:controlr
  • 4
  • 4
8 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
procedure TForm1.GetFileFromWeb;
var astream: TMemoryStream;
  aFile: string;
begin
  aStream := TMemoryStream.Create;
  try
    idHttp1:=TIdHTTP.Create(self);
    try
      aFile := 'http://www.google.com';
      idHttp1.Get(Site, aStream);
    finally
      idHttp1.Free;
    end;
    // do something with the stream
  finally
    aStream.Free;
  end;
end;  
0
 

Author Comment

by:controlr
Comment Utility

thats look good
but why i cant load the stream to an Timage?

example:
aFile := 'http://www.makav.co.il/logo.bmp';
  Image1.Picture.Bitmap.LoadFromStream(astream);

thanks for helping
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
is there a bitmap in the picture before you load it ?

load a bitmap in the picture first with the ide
I can't be anything, like a white bitmap of 1x1 square

then try again
0
 

Author Comment

by:controlr
Comment Utility
i tried that allready and it does not work :(
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
does loading the file from the website work ?
0
 

Author Comment

by:controlr
Comment Utility
i think yes because when i save it to file i see the image.
but i want to save it to stream and then to load it directly to the timage without using the disk
0
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
i can't test the Get function here as i am behind a firewall,
i'll test the other stuff

you need to set the stream to the beginning




procedure TForm1.GetFileFromWeb;

var astream: TMemoryStream;

  aFile: string;

begin

  aStream := TMemoryStream.Create;

  try

    idHttp1:=TIdHTTP.Create(self);

    try

      aFile := 'http://www.google.com';

      idHttp1.Get(Site, aStream);

    finally

      idHttp1.Free;

    end;

    aStream.Seek(soFromBeginning, 0);

    Image1.Picture.Bitmap.LoadFromStream(aStream);

  finally

    aStream.Free;

  end;

end;  

Open in new window

0
 

Author Comment

by:controlr
Comment Utility
thanks a lot man!!!!
its working
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now