开发者

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 );
   开发者_JS百科     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!


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


1) Where is your code located?

The hInstance will get the resource from the current process .exe file. In short, hInstance is common to the whole exe, whatever form you're using in it.

So the 'ajax-loader' resource must be in the .exe which contains this code.

2) Is your resource well created?

Use a resource explorer to list the resources inside your exe. You must match the resource name (i.e. 'ajax-loader') and the resource type, which must be set to value 10. For instance, your .rc file should look like this:

ajax-loader 10 "ajax-loader.gif"

I'm not sure the '-' char is allowed in resource name, but I guess this is OK.


You will want to change the way you reference RT_RCDATA. This method works for me:

rs := tResourceStream.Create(hInstance,'imgname', MakeIntResource(RT_RCDATA));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜