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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AVIs within form?

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
0
0
GB
Hi, basically I want to store some AVI files in a DLL or dat file (I know how to do that except for what type of resource to call them) and then display them on one of my forms (only one of them at any time).

At the moment my program just opens the file with a system call because I have the originals available but I don't want to have to distribute them all individually.

I have tried the Media Player and OLE Container components (Delphi 7) but they left me thoroughly confused, so any advice on the best way to achieve this?
 
Hi :)

You can the use the TAnimate component to play Avi's embedded in the exe's resource.



Just a small note,
If you have an older version of Delphi running you would need to compile the rc into file into a res file using BRCC32.exe (Borland's command line resource compiler) and then include it in the project with this line such as
{$R RCfile.res}
 
Another step by step guide

Just copy paste the one line below into NotePad. Change the filename and description if needed.

AVIMovie AVI "Somefile.avi"


So it goes like {descr.} {file type} {"filename"}

Save the file with a .rc extention, e.g. RCfile.rc, save it in the project's folder. Now then, add the rc file to the project.The IDE should automatically make a .res file when you compile the project. The AVI should be embedded in the exe.

To play the file from the resource,
Animate1.ResName := 'AVIMovie';
Animate1.Active := true;

 
Yeah, I know how to create resource files, but thanks for the advice, someone else might find it useful.

Can you adapt the above code to read it in from an external resource file? This particular application works better that way. I'll check out the component and tell you if I get there first.
 
Got it, simply set ResHandle to the handle of the resource file first. :)
 
Ok, freaky problem.

My resource file is as this (only one entry right now to make it easier to debug):

100 AVI "Filename"

I decided to use numbers for various reasons I won't go into and obviously "Filename" has the actual filename, that's just there because the real filename is very long and has no bearing on this.

My resource file compiles into the DLL fine, right file size etc.

My code to read the avi out is:

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;

The 100 is hard coded in for now to remove one thing which could go wrong. I've done various showmessage() lines and LibraryID has a real value and the file is in the right place (the dynamically created ResID was also right but I hard coded it for now anyway). video is the TAnimate component.

Basically I run the program and when it hits those lines it says simply:
&quot;Cannot open AVI&quot;
No help or anything from it.

Any thoughts anyone?
 
you just load the library, now you must load the resource from your library into memory. don't have code for an AVI resource but I'm sure you can learn something from this code, I use it to load JPEG resources from a DLL.

procedure LoadJPEGFromRes(TheJPEG : string; ThePicture : TPicture;PIC_DLL : Thandle);

var MemHandle : THandle;
MemStream : TMemoryStream;
ResHandle : THandle;
ResPtr : PByte;
ResSize : Longint;
JPEGImage : TJPEGImage;

begin
ResHandle := FindResource(PIC_DLL, PChar(TheJPEG), 'JPEG');
MemHandle := LoadResource(PIC_DLL, ResHandle);
ResPtr := LockResource(MemHandle);
MemStream := TMemoryStream.Create;
JPEGImage := TJPEGImage.Create;
ResSize := SizeOfResource(MD_DLL, ResHandle);
MemStream.SetSize(ResSize);
MemStream.Write(ResPtr^, ResSize);
FreeResource(MemHandle);
MemStream.Seek(0, 0);
JPEGImage.LoadFromStream(MemStream);
ThePicture.Assign(JPEGImage);
JPEGImage.Free;
MemStream.Free;
end;

greetings,

 
The example on the Delphi site (linked to above) says to use code as I have done there. It's one of the good examples of an object oriented approach within Delphi, you give the object only the information it needs and it does everything else itself.

Also, you may find it easier to load JPEG like this:

Code:
procedure TfrmMain.LoadDLLPic(var img:TImage; PicName:String);
var
   JPEGIn:TJPEGImage;
   Res:TResourceStream;
   LibraryID:THandle;
   Temp:PChar;
begin
   LibraryID := LoadLibrary({DLL address here});
   If LibraryID <> 0 then
   begin
      Res := TResourceStream.Create(LibraryID, PicName, RT_RCDATA);
      try
         JPEGIn := TJPEGImage.Create;
         img.Picture.Graphic := JPEGIn.Create;
         img.Picture.Graphic.LoadFromStream(Res);
         JPEGIn.Free;
      finally
         Res.Free;
      end;
   end
end;

Much shorter and easier to follow.
 
No thoughts on this anyone? I still haven't figured it out :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top