Search code examples
delphiresourcesstreamanimated-gifinstances

Load GIF from Resource to Dynamic form


I have this piece of code:

SELDR_WH := FindControl(FindWindow(nil,'PhoneDB Filtering')) as TForm;
 if seldr_wh <> nil then
  begin
    SELDR_WH.ClientHeight := SELDR_WH.ClientHeight + 20;
    gif := TGIFImage.Create;
    with gif do begin
      Parent := SELDR_WH;
      Top := SELDR_WH.ClientHeight - 20;
      Left := 30;
      try
        rs := TResourceStream.Create( hInstance, 'ajax-loader', RT_RCDATA );
        gif.LoadFromStream(rs);
      except on Exception do begin
          rs.free;
          gif.free;
        end;
      end
    end;
  end;

Code is pretty obvious, I think. No explanations ...

But - issue is that I am not able to load this GIF resource to gif component -> EResNotFound ...

Problem is in hInstance parameter as stated here: http://www.codeproject.com/Messages/931171/Re-The-difference-between-HWND-and-HINSTANCE.aspx

But - How to load it? Effect of failed loading is that Main form is set as Child form of SELDR ( SELDR_WH ) form.

Any help appreciated. Thanks!


Solution

  • try to check if your gif image was properly set. I think you need to add the ajax-loader.gif to your resource. then name it with ajax-loader with type RT_RCDATA . how to do it, goto Project>Resources>add the file, resource identifier = ajax-loader Type = RT_RCDATA. it surely work. i tested it. your code is working fine. if it external, make sure you have to laod the resource.dll first. or maybe the problem is'nt really there..

    only loading images it works fine