调用资源文件*.res后,怎样释放内存 ( 积分: 100 )

  • 主题发起人 主题发起人 lsf520
  • 开始时间 开始时间
L

lsf520

Unregistered / Unconfirmed
GUEST, unregistred user!
调用资源文件*.res后,我想从内存中释放已没再被使用的那部分资源(音乐自动播放)<br>比如:<br>  一个资源文件为:music.res 它是由music.rc生成的, music.rc 里面包含:<br>  music01 mp3 &quot;当爱在靠近.mp3&quot;<br> &nbsp; &nbsp;music02 mp3 &quot;爱海滔滔.mp3&quot;<br> &nbsp; &nbsp;music03 mp3 &quot;听,是谁在唱歌.mp3&quot;<br><br>现在已经播放了music01首音乐,进入播放music02首音乐时,我想把music01从内存中释放。<br>有哪位能手帮帮忙!!!<br>急着用,请高手快快来啊!!!!!
 
调用资源文件*.res后,我想从内存中释放已没再被使用的那部分资源(音乐自动播放)<br>比如:<br>  一个资源文件为:music.res 它是由music.rc生成的, music.rc 里面包含:<br>  music01 mp3 &quot;当爱在靠近.mp3&quot;<br> &nbsp; &nbsp;music02 mp3 &quot;爱海滔滔.mp3&quot;<br> &nbsp; &nbsp;music03 mp3 &quot;听,是谁在唱歌.mp3&quot;<br><br>现在已经播放了music01首音乐,进入播放music02首音乐时,我想把music01从内存中释放。<br>有哪位能手帮帮忙!!!<br>急着用,请高手快快来啊!!!!!
 
不是吧,高手都跑哪去了?
 
没人会吗?<br>大富翁呢
 
你读取到什么地方就释放什么就可以了
 
delphilxh &nbsp; &nbsp;那该怎么释放?<br>能把相关的代码附上去么?
 
你把你的代码贴上来,我才能知道你到底要怎么释放呀
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, MPlayer, StdCtrls, CheckLst, ExtCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Play: TButton;<br> &nbsp; &nbsp;MediaPlayer1: TMediaPlayer;<br> &nbsp; &nbsp;CheckListBox1: TCheckListBox;<br> &nbsp; &nbsp;Next: TButton;<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;procedure Resource;<br> &nbsp; &nbsp;procedure PlayClick(Sender: TObject);<br> &nbsp; &nbsp;procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure NextClick(Sender: TObject);<br> &nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>{$R lsf.res}<br><br>procedure TForm1.PlayClick(Sender: TObject);<br>begin<br> &nbsp;MediaPlayer1.Close;<br> &nbsp;DeleteFile('c:/temp.mp3');<br> &nbsp;Resource;<br> &nbsp;MediaPlayer1.FileName:='c:/temp.mp3';<br> &nbsp;MediaPlayer1.open;<br> &nbsp;MediaPlayer1.Play;<br> &nbsp;Timer1.Enabled :=true;<br>end;<br><br>procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br> &nbsp; MediaPlayer1.Close;<br> &nbsp; DeleteFile('c:/temp.mp3');<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp; Checklistbox1.ItemIndex := 0;<br>end;<br><br>procedure TForm1.NextClick(Sender: TObject); //下一首<br>begin<br> &nbsp; &nbsp; &nbsp;if Checklistbox1.ItemIndex =Checklistbox1.Count-1 then<br> &nbsp; &nbsp; &nbsp; &nbsp; Checklistbox1.ItemIndex :=0<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; Checklistbox1.ItemIndex :=Checklistbox1.ItemIndex+1;<br> &nbsp; &nbsp; &nbsp;Form1.PlayClick(sender);<br>end;<br><br>//主要在下面这段 如:当前Checklistbox1.Items.Strings[Checklistbox1.ItemIndex]:=music01<br>现在 Checklistbox1.ItemIndex:=Checklistbox1.ItemIndex+1 &nbsp;----&gt;music02<br>要删除内存中music01所占的内存资源,该如何?<br><br>procedure TForm1.Resource;  //读取资源、释放已经没用的资源(未实现)<br>var<br> &nbsp;R: TResourceStream;<br>begin<br> &nbsp;r:=TResourceStream.Create(HInstance, Checklistbox1.Items.Strings[Checklistbox1.ItemIndex] , 'mp3');<br> &nbsp;r.SaveToFile('c:/temp.mp3');<br> &nbsp;r.Free;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> &nbsp; if MediaPlayer1.Position &gt;=MediaPlayer1.Length then<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp;if Checklistbox1.ItemIndex =Checklistbox1.Count-1 then<br> &nbsp; &nbsp; &nbsp; &nbsp; Checklistbox1.ItemIndex :=0<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; Checklistbox1.ItemIndex :=Checklistbox1.ItemIndex+1;<br> &nbsp; &nbsp; &nbsp;Form1.PlayClick(sender);<br> &nbsp; end;<br>end;<br><br>end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部