views:

53

answers:

3

Hi, 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!

A: 

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.

A. Bouchez
1) All is OK ; 2) All is OK ; - symbol is allowed. Another suggestions ... ?
HX_unbanned
Did you try to load the resource in a small exe? Link the same .res file, then load the resource.
A. Bouchez
A: 

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

rs := tResourceStream.Create(hInstance,'imgname', MakeIntResource(RT_RCDATA));
skamradt
It's exactly the same as tResourceStream.Create(hInstance,'imgname', RT_RCDATA);
A. Bouchez
Nop. Does not change a thing ...
HX_unbanned
Anything else to offer as solution?
HX_unbanned
+3  A: 

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

XBasic3000
maybe there is a problem on naming the image, or the library is loaded yet. or something is missing like {$R ERes.res}
simply_anny