Getting an image from a URL with parameters lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- fapplin · 2015-09-24 21:38 Hi, I'm trying to use the following function that I wrote to grab an image created by a web-site and use it as a picture image on my form. I do get an image, but it's acting like all the URL parameters are being ignored. Here is the call and the function. When I look at imageName in the debugger, I see: 'www.astrobot.eu/skymapserver/skymap?type=png&size=800&colorset=0&lang =en&lon= -78.48&lat=37.33&city=Gladstone&timezone=EST&deco=16399' If you take the URL and use it in a browser - you'll see an image with Gladstone in the upper right-hand corner. That is the way the image is suppose to look. If you strip the URL parameters off: 'www.astrobot.eu/skymapserver/skymap' This is what I see generated by my program. It's like HTTPSend.HttpGetBinary is not using the parameters. Does anyone have any suggestions?? Thanks. procedure TFormNightSky.FormCreate(Sender: TObject); var   imageStream : TMemoryStream; begin    imageStream := CreateNightSkyImage(-78, 48, 37, 33, 'Gladstone', 'EST');    imageStream.SaveToFile('CurrentNightSky.png');    ImageNightSky.Picture.LoadFromFile('CurrentNightSky.png'); end; function CreateNightSkyImage(LonDeg : integer; LonMin : integer; LatDeg : integer;                                     LatMin : integer; City : String; TimeZone : String) :  TMemoryStream; var   imageName : String;   imageStream : TMemoryStream; begin    imageName := 'www.astrobot.eu/skymapserver/skymap?' +               'type=png' +               '&size=800' +               '&colorset=0' +               '&lang=en' +              '&lon= ' + Trim(IntToStr(LonDeg) + '.' + IntToStr(LonMin)) +              '&lat=' + Trim(IntToStr(LatDeg) + '.' + IntToStr(LatMin)) +              '&city=' + City +              '&timezone=' + TimeZone +              '&deco=16399';    imageStream := TMemoryStream.Create;    if (HTTPSend.HttpGetBinary(imageName, imageStream)) then    begin        imageStream.Seek(0, soFromBeginning);    end;    result := imageStream; end; ---------------------------------------------------------------------- derek.john.evans · 2015-09-24 23:15 Small bug in your URL generation code: '&lon= ' << There is a space. **EDIT** Also, You dont seem to have the protocol at the start of the URL. ie: http:// As a tip, module-ize your code a little better. eg: Downloading a TPicture from a URL should be one function. Downloading a TPicture from Astrobot should be a second function. You shouldn't create classes (ie: TMemoryStream) in a function and return it. It makes it unclear as to who (what code) is responsible for it (ie: freeing the object). I know a lot of people do it, but I dont think its good coding. Example: if HttpGetBinary raised an exception, then the TMemoryStream would not be freed. Usually, to code like that, you would need to catch exceptions for HttpGetBinary. If an exception is thrown, then TMemoryStream is freed, and the exception is re-raised. Simple solution: Don't return class objects. Always pass class objects as parameters. (Unless, you are writing a class, in which case, the class should free its objects in its destructor, which is another story) This works for me: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses fphttpclient; procedure PictureLoadFromUrl(const APicture: TPicture; const AUrl: String);var  LMemoryStream: TMemoryStream;begin  LMemoryStream := TMemoryStream.Create;  try    TFPHTTPClient.SimpleGet(AUrl, LMemoryStream);    LMemoryStream.Position := 0;    APicture.LoadFromStream(LMemoryStream);  finally    FreeAndNil(LMemoryStream);  end;end; procedure PictureLoadFromAstrobot(const APicture: TPicture; const ALonDeg, ALonMin, ALatDeg, ALatMin: Integer;  const ACity, ATimeZone: String);begin  PictureLoadFromUrl(APicture, 'http://www.astrobot.eu/skymapserver/skymap?' + 'type=png' +    '&size=800' + '&colorset=0' + '&lang=en' + '&lon=' + IntToStr(ALonDeg) + '.' +    IntToStr(ALonMin) + '&lat=' + IntToStr(ALatDeg) + '.' + IntToStr(ALatMin) + '&city=' +    ACity + '&timezone=' + ATimeZone + '&deco=16399');end; procedure TForm1.FormCreate(Sender: TObject);begin  PictureLoadFromAstrobot(Image1.Picture, -78, 48, 37, 33, 'Gladstone', 'EST');end;   ** EDIT ** I would probably also change the URL generation to a Format() function. That way, the URL template can be a constant which can be easily updated. ---------------------------------------------------------------------- fapplin · 2015-09-25 11:16 Thanks for the help and the suggestions. I'm brand new to Lazarus and Free Pascal (but, a programmer for 30 years in different languages and platforms). This is being done for a small project on a Raspberry Pi. Frank