用delphi7做的mp3歌词显示!!
编译不通过,
错误是: Project project1.exe raised exception class EConverError with message "Label8'is not a valid integer value',Process stopped. 代码:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, MPlayer, StdCtrls;type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    MediaPlayer1: TMediaPlayer;
    Timer1: TTimer;
    Timer2: TTimer;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
    var     i:variant;
begin   // 显示歌曲总时间与当前播放到的时间
        // 为了减轻程序的处理难度,label1 我们只精确到秒,所以用了 trunc 函数
  label1.Caption := FloatToStr(trunc(MediaPlayer1.Position / 1000));  //当前时间
  label2.Caption :=floattostr(trunc(MediaPlayer1.Length / 1000));   // 歌曲总时间
  label3.Caption :=inttostr(memo1.lines.Count) ;                // LRC文件行数
     try
            // 让label8的内容从0开始直到memo1.lines的行数为止,不断循环
// 为接下 去timer2中变量 i提供所有行的数值,从而实现不断得到memo2 与  
         //  memo3 的各行内容,从而判断与当前歌曲的已播时间和显示相应歌词内容
        if   strtoint(label8.Caption) < strtoint(label3.Caption) 
            then  label8.Caption:=inttostr(strtoint(label8.Caption )+1 )  // 每次加1
        else  label8.Caption:='0'   //到达行数值时,重新变为0
 except 
   exit
     end;
    if   strtoint(label4.Caption)<= strtoint (label3.Caption)-2
       then 
      begin
        i:=strtoint(label4.Caption) +1;
        label5.Caption :=memo1.Lines[i];
        label4.Caption :=i ;
 // label4是一个计数器,(从0到总行数少1è即所有行的内容, 循环一次,)
//因为memo.lines是从0开始的。这样label5就可以将memo1的每行内容都取出来, 
            try
              label6.Caption:=inttostr((strtoint(copy(label5.Caption,2,2))*60)
              +strtoint(copy(label5.Caption ,5,2)));  
                   //label6 将memo1中 如 [01:02.00]转成 62  ,即时间标签变秒数
             memo2.Lines.Add(copy(label6.Caption ,1,4)) ;    //时间秒数放到memo2中
             memo3.Lines.Add(copy(label5.Caption,11,40));  //歌词内容放到memo3中
//取 [xx:xx.xx]后面的歌词内容 即从第11个字符开始取,40 是自己设的,
// 稍大一些可以保证取大最长的歌词内容,但一般20个汉字差水多了
         except        
              exit       
           end;               
      end;      
 end;
procedure TForm1.Timer2Timer(Sender: TObject);
var i:int64;    
begin
  i:=strtoint(label8.Caption );  // label8在不断地改变,则i是从0-所有行的不断循环
if  memo2.Lines[i]=label1.Caption //当memo2中的时间与label1(即歌曲行进的时间)相同时
 then  label9.Caption:=memo3.Lines[i] 
         // 那么就显示相应的memo3的lines的该行内容。就成功显示了 LRC 歌词了
end;
 procedure TForm1.FormCreate(Sender: TObject);
begin
 if  fileexists ('test.mp3')  then
   begin
      MediaPlayer1.FileName:='test.mp3';
          // 请在当程序的当前目录下放一个test.mp3音乐文件或直接用我的例子
      MediaPlayer1.AutoOpen:=True;          // 置 mediaplayer属性
      MediaPlayer1.Open;
      memo1.Lines.LoadFromFile('test.lrc')    // 读取歌词文件到memo1中
   end;
end; end.

解决方案 »

  1.   

    strtoint改成strtointdef
    lable8存在无法转换成数值的内容
      

  2.   

    procedure TForm1.Timer1Timer(Sender: TObject);
       var     i:variant;
    begin   // 显示歌曲总时间与当前播放到的时间
            // 为了减轻程序的处理难度,label1 我们只精确到秒,所以用了 trunc 函数
      label1.Caption := FloatToStr(trunc(MediaPlayer1.Position / 1000));  //当前时间
      label2.Caption :=floattostr(trunc(MediaPlayer1.Length / 1000));   // 歌曲总时间
      label3.Caption :=inttostr(memo1.lines.Count) ;                // LRC文件行数
         try
                // 让label8的内容从0开始直到memo1.lines的行数为止,不断循环
    // 为接下 去timer2中变量 i提供所有行的数值,从而实现不断得到memo2 与
             //  memo3 的各行内容,从而判断与当前歌曲的已播时间和显示相应歌词内容
            if   strtointdef(label8.Caption,0)  < strtointdef(label3.Caption,0)
                then  label8.Caption:=inttostr(strtointdef(label8.Caption,0 )+1 )  // 每次加1
            else  label8.Caption:='0'   //到达行数值时,重新变为0
     except
       exit
         end;
        if   strtointdef(label4.Caption,0) <= strtoint (label3.Caption)-2
           then
          begin 
            i:=strtoint(label4.Caption) +1;
            label5.Caption :=memo1.Lines[i];
            label4.Caption :=i ;
     // label4是一个计数器,(从0到总行数少1è即所有行的内容, 循环一次,) 
    //因为memo.lines是从0开始的。这样label5就可以将memo1的每行内容都取出来,
                try
                  label6.Caption:=inttostr((strtoint(copy(label5.Caption,2,2))*60)
                  +strtoint(copy(label5.Caption ,5,2)));
                       //label6 将memo1中 如 [01:02.00]转成 62  ,即时间标签变秒数
                 memo2.Lines.Add(copy(label6.Caption ,1,4)) ;    //时间秒数放到memo2中
                 memo3.Lines.Add(copy(label5.Caption,11,40));  //歌词内容放到memo3中
    //取 [xx:xx.xx]后面的歌词内容 即从第11个字符开始取,40 是自己设的, 
    // 稍大一些可以保证取大最长的歌词内容,但一般20个汉字差水多了
             except
                  exit
               end;
          end;
    end;
    procedure TForm1.Timer2Timer(Sender: TObject);
    var i:int64;
    begin
      i:=strtointdef(label8.Caption,0 );  // label8在不断地改变,则i是从0-所有行的不断循环
    if  memo2.Lines[i]=label1.Caption //当memo2中的时间与label1(即歌曲行进的时间)相同时
     then  label9.Caption:=memo3.Lines[i]
             // 那么就显示相应的memo3的lines的该行内容。就成功显示了 LRC 歌词了
    end;