OnFormat and C++Builder 6

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

OnFormat and C++Builder 6

Postby PatD » May 29th, 2007, 5:36 pm

The OnFormat event of the TLiveAudioPlayer seems to be not compatible with C++Builder 6. Here's the code I use :

Code: Select all
void __fastcall TdtaTapi::pPlayerFormat(TObject *Sender,
      PWaveFormatEx pWaveFormat, bool &FreeIt)
{
    pWaveFormat=new WAVEFORMATEX;
    FreeIt=true;
    pWaveFormat->wFormatTag=WAVE_FORMAT_PCM;
    pWaveFormat->nChannels=1;
    pWaveFormat->nSamplesPerSec=8000;
    pWaveFormat->nAvgBytesPerSec=16000;
    pWaveFormat->nBlockAlign=2;
    pWaveFormat->wBitsPerSample=16;
    pWaveFormat->cbSize=0;
}


When I debug your Delphi code when leaving the event, I see that pWaveFormat retrieves its value before the event call. So, the following instruction fails :
if Success(WaveOutOpen(nil, DeviceID, pWaveFormat, 0, 0, WAVE_FORMAT_QUERY)) then

and FreeMem(pWaveFormat); throws an exception.

Since the predefined values of wave format do not match my format, it seems this event is mandatory. Is there another way to ask to your control to use my WAVEFORMATEX structure ?

Thanks.
PatD
Active Member
Active Member
 
Posts: 8
Joined: October 18th, 2006, 4:19 pm

Postby Kambiz » May 30th, 2007, 12:34 am

In Delphi the OnFormat event is defined as follow:

Code: Select all
OnFormat(Sender: TObject; out pWaveFormat: PWaveFormatEx; var FreeIt: Boolean)


Pay attention to out modifier in front of pWaveFormat parameter. In Delphi to make a parameter call by reference, there are three directives: const, var, and out. Here is the definition of these modifiers in Delphi:

  • const
    A const parameter is read-only.
  • var
    A var parameter is passed by reference. The function or procedure can store output in to a var parameter.
  • out
    An out parameter, like a var parameter, is passed by reference. With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to. The out
    parameter is for output only; that is, it tells the function or procedure where to store output, but doesn’t provide any input.
Seems to be a bug in the BCB 6 compiler, and ignores the out modifier.

The solution is quite easy. In the package's units, replace all out occurrences to var.

Please consider that the Wave Audio package is not tested on BCB. Therefore you may encounter other problems at runtime. For example, I think it is not the right way to release memory allocated using new operator by FreeMem procedure.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby PatD » May 30th, 2007, 7:00 am

You're right. I changed

TWaveAudioGetFormatEvent = procedure(Sender: TObject;
out pWaveFormat: PWaveFormatEx; var FreeIt: Boolean) of object;

to

TWaveAudioGetFormatEvent = procedure(Sender: TObject;
var pWaveFormat: PWaveFormatEx; var FreeIt: Boolean) of object;

and now the structure address is correctly returned. I now use a static structure and set FreeIt to false.

Thanks for your help.
PatD
Active Member
Active Member
 
Posts: 8
Joined: October 18th, 2006, 4:19 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron