views:

89

answers:

2

Hi All

I had my old MP3 Id3 tag reader recompiled under D2010 and it seems it won't find the tags anymore.

code is farily simple, but it doesn't work. The debugger shows a lots of zero and then chineese signs in the results!

    var dat:file of char;
    id3:array [0..TAGLEN] of Char;  //is 0..127 for ID3 v1
begin
   vValid:=True;
   if FileExists(vFilename) then begin
      assignfile(dat,vFilename);
      If (FileGetAttr(vFilename)>32) or (FileGetAttr(vFilename)=1) then
        Filemode:= 0
      Else
        Filemode:= 2;
      reset(dat);
      seek(dat,FileSize(dat)-128);
      blockread(dat,id3,128);
      closefile(dat);
      vMP3tag:=copy(id3, 0, 3);
      if vMP3Tag='TAG' then begin
         vTitle:=strip(copy(id3, 4, 30),' ');
         vArtist:=strip(copy(id3, 34, 30), ' ');

I heard something about Unicode, and PansiChar, but I still don't understand much what these do anyway :)

thanks for looking

A: 

Oh!

it seems like AnsiCHar instead of Char is the way to go in D2010.

Ansi-char-them-all!

DomS
Actually, without specifying an encoding, you don't want AnsiChar for a most things.
Jeroen Pluimers
+3  A: 

Try this:

 var dat:file of AnsiChar;
id3:array [0..TAGLEN] of AnsiChar;  //is 0..127 for ID3 v1

That is of course if your file is ansi-based instead of unicode based. I have no idea what might be in an id3 tag of an mp3 file.

If you want to understand the difference, this white paper explained it all to me. Basically Unicode uses more memory space to store a single character (like 4 times the amount of an ansi character), but they allow characters like ie Chinese and Japanese, which ansi doesn't provide. Just read the white paper, then it'll all be clear.

In short, Ansichar and Ansistring is what used to be a string in Delphi before D2009. In those days your application wouldn't be unicode compatible (you couldn't type chinese characters by default). As from D2009, the definition of a string changed from an ansistring to a widestring and ansichar to widechar. That means your application will be unicode by default. But old code, expecting strings to be ansicode, need to be adapted to reflect that change. Your code said char, meaning ansichar to pre-D2009 compilers, but widechar to D2009+ compilers. In other words, the new compilers read your code differently.

I hope that explains it a bit.

Brave Cobra
This code is implemented for id3 v1 and v1.1 tags which were ASCII/ANSI. id3 v2+ introduced support for Unicode but v2+ tags are are implemented completely differently from v1 (the system really isn't v2 at all, but v1.0 of an entirely new system!) but in any event, v2+ tags clearly aren't a concern for the code posted with the question, and so Unicode support is not a concern either.
Deltics
thanks for the explanations. I feel unicodified now :)I'm still having a problem with an example of communication between two apps, shown at http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htmI think there is something uncontrolable that happen to the data while being sent, but I tried all king of char and couldn't get it going perfect yet..
DomS