Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resource file / TAnimate problem

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Hi, I have a problem where a TAnimate component refuses to open an AVI from a .dll file I compiled.

My resource file is written as:

Code:
100 AVI "[Flename]"

It compiles correctly (or I'm guessing it does as the filesize is correct).

Then I use Delphi to compile it into a .dll with the following:

Code:
Library s1;

{$R *.RES}
{$R season1.res}

Begin
End.

The result of this also has the correct file size.

The TAnimate has the following code to load this:

Code:
   ExePath := ExtractFilePath(Application.ExeName);
   Temp := PChar(ExePath+'s1.dll');
   LibraryID := LoadLibrary(Temp);
   If LibraryID > 0 then
   begin
      video.Visible := True;
      video.ResHandle := LibraryID;
      video.ResID := 100;
   end;

ExePath is a string, Temp is a PChar and LibraryID is a THandle.

As far as I can tell from my debugging attempts, it fails on the line that sets ResHandle. I've checked and the filename is correct. LibraryID is a number around 15728640 (that was what it was when I checked just now).

The error message it gives me is simply "Cannot open AVI" with no extra help.

Any ideas?
 
ok this is really stupid,

after spending some time comctrls unit I saw this :

procedure TAnimate.SetResHandle(Value: THandle);
begin
if FResHandle <> Value then
begin
FResHandle := Value;
FRecreateNeeded := GetComCtlVersion < ComCtlVersionIE4;
FCommonAVI := aviNone;
FFileName := '';
if FResHandle = 0 then SetOpen(False) else Reset;
end;
end;

procedure TAnimate.SetResId(Value: Integer);
begin
if FResId <> Value then
begin
FResId := Value;
FRecreateNeeded := ((FCommonAVI <> aviNone) or (FFileName <> '')) and
(GetComCtlVersion < ComCtlVersionIE4);
FCommonAVI := aviNone;
FFileName := '';
FResName := '';
if Value = 0 then SetOpen(False) else Reset;
end;
end;

I made the call to reset in bold because this function will be called after setting property resid or reshandle. Now here's the stupid part : calling reset will result into a OPEN attempt of the avi/resource. so after the line video.ResHandle := LibraryID; the component will try to load an AVI with resID 0!!! so simply changing your code to this will get things working :


ExePath := ExtractFilePath(Application.ExeName);
Temp := PChar(ExePath+'s1.dll');
LibraryID := LoadLibrary(Temp);
If LibraryID > 0 then
begin
video.Visible := True;
try
//catch raised exception here due to ResID = 0
video.ResHandle := LibraryID;
except
end;
video.ResID := 100;
// avi will be loaded!!!
end;


I tested this myself and it works like a charm.

greetings,

 
Now that's just really... there aren't words for it are there?

This means that the example code on the Borland site (which is what I based this on) won't work!
 
Still won't work, same error message. What the hell is going on here? I'm baout ready to give up with this thing.
 
The line still fails and I think ResHandle doesn't get set right, it gives me the error twice, presumably the second being the ResID line because it can't find the library.
 
does your delphi debugger stops on exceptions??

check tools menu - debugger options - language exceptions tab. uncheck &quot;stop on delphi exceptions&quot;

 
D7

Unchecked Delphi exceptions, which stops the first error message. The second one is still displayed, so the ResID line is obviously failing as well because the ResHandle line dies in whichever it prefers this week.

 
Ok, just trying to open the original file, the error message still pops up, but no exceptions occur. Also, I just noticed in the help in the filename property that the sound is ignored when the file is opened. In this case is there a component that will play the video with sound (or that can play it at all)?
 
Yeah, this is comes of using a component that someone suggested without first checking it was what you needed.

Oh well, I learned some things about some things, so I guess that's what counts in the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top