Author Topic: Filenames with umlaut: BASS_ERROR_FILEOPEN (Free Pascal)  (Read 878 times)

stem

  • Posts: 5
Hi,

I'm using the latest version of Lazarus/Free Pascal (Windows) with bass24-delphidyn.

The following line gives me error code 2 (BASS_ERROR_FILEOPEN), if the filename contains an umlaut:

Code: [Select]
global_bass_hs := BASS_SampleLoad(False, f, 0, 0, 1, BASS_SAMPLE_OVER_POS {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});   

The check
Code: [Select]
if (FileExists(f) = True)says, that the file exists.

What am I doing wrong?

Thank you!  :)


stem

Chris

  • Posts: 1860

stem

  • Posts: 5
Lazarus 1.8.4
FPC 3.0.4

Ian @ un4seen

  • Administrator
  • Posts: 21370
From the link that Chris posted, it looks Lazarus can use UTF-8 or UTF-16 strings. On Windows, you want to use UTF-16 (the BASS_UNICODE flag tells BASS to expect that).

stem

  • Posts: 5
May I show you my complete procedure? With umlaut characters in the filename, I get error code 2 in line 12 (because global_bass_hs is 0).

Code: [Select]
procedure bass_playsample(filename: string);
var
  f: string;
  hc: HCHANNEL;
begin
  f := ExpandFileName(filename);

  if (FileExists(f) = True) then
  begin
    global_bass_hs := BASS_SampleLoad(False, PChar(f), 0, 0, 1, BASS_SAMPLE_OVER_POS {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});

    if (global_bass_hs = 0) then
    begin
      Application.MessageBox(PChar(IntToStr(BASS_ErrorGetCode())), 'error sample loading, error code: ', MB_ICONERROR);

      Exit();
    end;

    hc := BASS_SampleGetChannel(global_bass_hs, False);

    BASS_ChannelPlay(hc, False);
  end
  else
  begin
    Application.MessageBox(PChar(f), 'file does not exist', MB_ICONERROR);
  end;
end;

How must I call BASS_SampleLoad correctly?

Thank you!  :)


stem

Falcosoft

  • Guest
Try this instead:
Code: [Select]
procedure bass_playsample(filename: string);
var
  f: string;
  uf: UnicodeString;
  hc: HCHANNEL;

begin
  f := ExpandFileName(filename);

  if (FileExists(f) = True) then
  begin
    uf := f;
    global_bass_hs := BASS_SampleLoad(False, PWideChar(uf), 0, 0, 1, BASS_SAMPLE_OVER_POS  or BASS_UNICODE);

    if (global_bass_hs = 0) then
    begin
      Application.MessageBox(PChar(IntToStr(BASS_ErrorGetCode())), 'error sample loading, error code: ', MB_ICONERROR);

      Exit();
    end;

    hc := BASS_SampleGetChannel(global_bass_hs, False);

    BASS_ChannelPlay(hc, False);
  end
  else
  begin
    Application.MessageBox(PChar(f), 'file does not exist', MB_ICONERROR);
  end;
end;

stem

  • Posts: 5
Thank you, now it works!


stem