Discussion:
How to add BCB unit into Delphi unit?
(too old to reply)
James5950
2008-03-04 15:53:20 UTC
Permalink
Hello Sir,

I use a delphi form on my project, how to add BCB unit into delphi for
manipulation?
On BCB2007 I know add header file to another unit, but how to add header
file for delphi unit?

Thanks for any comments,

James
Clayton Arends
2008-03-04 17:28:55 UTC
Permalink
Post by James5950
On BCB2007 I know add header file to another unit, but how to add header
file for delphi unit?
Reading this again I wonder if you are trying to include the Delphi unit for
use in your C++ source. If so, when a Delphi unit is compiled by a
C++Builder project an HPP file is generated. So, for a Delphi unit file
named "somefuncs.pas" your C++ source should have this line:

#include "somefuncs.hpp"

The project does need to be configured to generate the C++ files from PAS
ones. Edit your project options, navigate to "Delphi Compiler | Other
Options". In the "C/C++ Output" area set the "Object files and headers"
configuration item to something like "Generate all C++ Builder files".

HTH,
Clayton
Clayton Arends
2008-03-04 17:21:46 UTC
Permalink
Post by James5950
Hello Sir,
There are more than one of us here plus a few "Madams".
Post by James5950
I use a delphi form on my project, how to add BCB unit into delphi for
manipulation?
Delphi units can be added to C++Builder projects but C++Builder units cannot
be added to Delphi projects.
Post by James5950
On BCB2007 I know add header file to another unit, but how to add header
file for delphi unit?
Delphi doesn't know how to use C/C++ header files. The only way to call C++
functions from a Delphi unit is to use callbacks or event handlers but
Delphi code will not be able to directly call a function or method in C++
source.

If you give an example of your configuration then someone here might be able
to further advise what you can do.

Clayton
James5950
2008-03-04 17:42:13 UTC
Permalink
Hi Clayton,
Post by Clayton Arends
There are more than one of us here plus a few "Madams".
You are right, I will fix it next time. printf("Hello World");
Post by Clayton Arends
If you give an example of your configuration then someone here might be
able to further advise what you can do.
I am another question above this. Is it enough for your advise?

Thank you,

Best regards,

James
James5950
2008-03-04 17:50:13 UTC
Permalink
Hello Clayton,

Below is the delphi code, it is a callback function.
I need receive this callback on BCB2007.

procedure Switch(double Index: longint); cdecl;
begin
case Index of
0 : PostMessage(MainForm.Handle, PM, AM, Index);
1 : MainForm.Switch(Index);
end;
end;
Clayton Arends
2008-03-04 18:37:34 UTC
Permalink
Post by James5950
Below is the delphi code, it is a callback function.
I need receive this callback on BCB2007.
procedure Switch(double Index: longint); cdecl;
begin
case Index of
0 : PostMessage(MainForm.Handle, PM, AM, Index);
1 : MainForm.Switch(Index);
end;
end;
It's a little unclear to me what you are asking for. How is this procedure
currently being used by the Delphi form? Can you show how you intend to use
the function -- whether it compiles correctly or not. Even showing pseudo
code might help in understanding what it is you want to accomplish.

Clayton
James5950
2008-03-05 00:14:49 UTC
Permalink
Below almost code about ASIO driver, that is audio driver use Delphi.
I need to manipulation these callback function on Bcb2007 when callback
message is coming.

procedure BufferSwitch(index: integer);
procedure BufferSwitchTimeInfo(index: integer; const params: TAsioTime);
procedure PMAsio(var Message: TMessage); message PM_ASIO;
procedure PMUpdateSamplePos(var Message: TMessage); message
PM_UpdateSamplePos;

James

// Delphi code start
unit main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, AsioList, OpenAsio, Asio, mmsystem;

const
// private message
PM_ASIO = WM_User + 1652; // unique we hope

// asio message(s), as wParam for PM_ASIO
AM_ResetRequest = 0;
AM_BufferSwitch = 1; // new buffer index in lParam
AM_BufferSwitchTimeInfo = 2; // new buffer index in lParam
// time passed in MainForm.BufferTime
AM_LatencyChanged = 3;

PM_UpdateSamplePos = PM_ASIO + 1; // sample pos in wParam (hi)
and lParam (lo)
type
TMainForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure ChangeEnabled;
procedure CloseDriver;
public
driverlist : TAsioDriverList;
Driver : IOpenAsio;
BuffersCreated : boolean;
IsStarted : boolean;
callbacks : TASIOCallbacks;
bufferinfo : PAsioBufferInfo;
BufferTime : TAsioTime;
ChannelInfos : array[0..1] of TASIOChannelInfo;
SampleRate : TASIOSampleRate;
procedure BufferSwitch(index: integer);
procedure BufferSwitchTimeInfo(index: integer; const params: TAsioTime);
procedure PMAsio(var Message: TMessage); message PM_ASIO;
procedure PMUpdateSamplePos(var Message: TMessage); message
PM_UpdateSamplePos;
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

function ChannelTypeToString(vType: TAsioSampleType): string;
begin
Result := '';
case vType of
ASIOSTInt16MSB : Result := 'Int16MSB';
ASIOSTInt24MSB : Result := 'Int24MSB';
ASIOSTInt32MSB : Result := 'Int32MSB';
ASIOSTFloat32MSB : Result := 'Float32MSB';
ASIOSTFloat64MSB : Result := 'Float64MSB';

end;
end;

// asio callbacks

procedure AsioBufferSwitch(doubleBufferIndex: longint; directProcess:
TASIOBool); cdecl;
begin
case directProcess of
ASIOFalse : PostMessage(MainForm.Handle, PM_ASIO, AM_BufferSwitch,
doubleBufferIndex);
ASIOTrue : MainForm.BufferSwitch(doubleBufferIndex);
end;
end;

procedure AsioSampleRateDidChange(sRate: TASIOSampleRate); cdecl;
begin
MessageDlg('The sample rate has been changed to ' + FloatToStr(sRate),
mtInformation, [mbOK], 0);
end;

function AsioMessage(selector, value: longint; message: pointer; opt:
pdouble): longint; cdecl;
begin
Result := 0;

case selector of
kAsioSelectorSupported : // return 1 if a selector is supported
begin
case value of
kAsioEngineVersion : Result := 1;
kAsioResetRequest : Result := 1;
kAsioBufferSizeChange : Result := 0;
kAsioResyncRequest : Result := 1;
kAsioLatenciesChanged : Result := 1;
kAsioSupportsTimeInfo : Result := 1;
kAsioSupportsTimeCode : Result := 1;
kAsioSupportsInputMonitor : Result := 0;
end;
end;
kAsioEngineVersion : Result := 2; // ASIO 2 is supported
kAsioResetRequest :
begin
PostMessage(MainForm.Handle, PM_Asio, AM_ResetRequest, 0);
Result := 1;
end;
kAsioBufferSizeChange :
begin
PostMessage(MainForm.Handle, PM_Asio, AM_ResetRequest, 0);
Result := 1;
end;
kAsioResyncRequest : ;
kAsioLatenciesChanged :
begin
PostMessage(MainForm.Handle, PM_Asio, AM_LatencyChanged, 0);
Result := 1;
end;
kAsioSupportsTimeInfo : Result := 1;
kAsioSupportsTimeCode : Result := 0;
kAsioSupportsInputMonitor : ;
end;
end;

function AsioBufferSwitchTimeInfo(var params: TASIOTime; doubleBufferIndex:
longint; directProcess: TASIOBool): PASIOTime; cdecl;
begin
case directProcess of
ASIOFalse :
begin
MainForm.BufferTime := params;
PostMessage(MainForm.Handle, PM_ASIO, AM_BufferSwitchTimeInfo,
doubleBufferIndex);
end;
ASIOTrue : MainForm.BufferSwitchTimeInfo(doubleBufferIndex, params);
end;

Result := nil;
end;

// Delphi Code End




//hpp file start
//-- user
supplied -----------------------------------------------------------

namespace Main
{
//-- type
declarations -------------------------------------------------------
class DELPHICLASS TMainForm;
class PASCALIMPLEMENTATION TMainForm : public Forms::TForm
{
typedef Forms::TForm inherited;

__published:
Stdctrls::TComboBox* DriverCombo;
Stdctrls::TGroupBox* DriverInfoBox;
void __fastcall FormCreate(System::TObject* Sender);
void __fastcall FormDestroy(System::TObject* Sender);
void __fastcall DriverComboChange(System::TObject* Sender);
void __fastcall ControlPanelBtnClick(System::TObject* Sender);
void __fastcall StartBtnClick(System::TObject* Sender);
void __fastcall StopBtnClick(System::TObject* Sender);
void __fastcall CreateBuffersBtnClick(System::TObject* Sender);
void __fastcall DestroyBuffersBtnClick(System::TObject* Sender);
void __fastcall Button1Click(System::TObject* Sender);

private:
void __fastcall ChangeEnabled(void);
void __fastcall CloseDriver(void);

public:
DynamicArray<Asiolist::TAsioDriverDesc > driverlist;
Openasio::_di_IOpenASIO Driver;
bool BuffersCreated;
bool IsStarted;
Asio::TASIOCallbacks callbacks;
Asio::TASIOBufferInfo *bufferinfo;
Asio::TASIOTime BufferTime;
Asio::TASIOChannelInfo ChannelInfos[2];
double SampleRate;
Classes::TMemoryStream* SoundStream;
void __fastcall BufferSwitch(int index);
void __fastcall BufferSwitchTimeInfo(int index, const Asio::TASIOTime
&params);
MESSAGE void __fastcall PMAsio(Messages::TMessage &Message);
MESSAGE void __fastcall PMUpdateSamplePos(Messages::TMessage &Message);
public:
#pragma option push -w-inl
/* TCustomForm.Create */ inline __fastcall virtual
TMainForm(Classes::TComponent* AOwner) : Forms::TForm(AOwner) { }
#pragma option pop
#pragma option push -w-inl
/* TCustomForm.CreateNew */ inline __fastcall virtual
TMainForm(Classes::TComponent* AOwner, int Dummy) : Forms::TForm(AOwner,
Dummy) { }
#pragma option pop
#pragma option push -w-inl
/* TCustomForm.Destroy */ inline __fastcall virtual ~TMainForm(void) { }
#pragma option pop

public:
#pragma option push -w-inl
/* TWinControl.CreateParented */ inline __fastcall TMainForm(HWND
ParentWindow) : Forms::TForm(ParentWindow) { }
#pragma option pop

};


//-- var, const,
procedure ---------------------------------------------------
static const Word PM_ASIO = 0xa74;
static const Shortint AM_ResetRequest = 0x0;
static const Shortint AM_BufferSwitch = 0x1;
static const Shortint AM_BufferSwitchTimeInfo = 0x2;
static const Shortint AM_LatencyChanged = 0x3;
static const Word PM_UpdateSamplePos = 0xa75;
extern PACKAGE TMainForm* MainForm;

} /* namespace Main */
using namespace Main;
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end
unit ----------------------------------------------------------------
#endif // Main

// hpp file end
Clayton Arends
2008-03-05 13:36:23 UTC
Permalink
Post by James5950
Below almost code about ASIO driver, that is audio driver use Delphi.
From what you've posted it appears that you are trying to create the sample
application that comes with the OpenASIO Delphi translation. Instead of
trying to hook into the existing form the better path would be to translate
the form to C++. I downloaded the OpenASIO Delphi translation package and
translated the unit main.pas found in "host" to C++. You can find the
translated source in borland.public.attachments in a post titled "For
James5950".

I do not have the ability to test that the source works. I could only test
that it compiles.

Good luck,
Clayton
James5950
2008-03-05 14:33:25 UTC
Permalink
Hello Clayton,

Thanks for your help. That's so great!

Best regards,
James

Remy Lebeau (TeamB)
2008-03-04 18:17:13 UTC
Permalink
Post by James5950
I use a delphi form on my project, how to add BCB unit into
delphi for manipulation?
You can't. Delphi does not have a C++ compiler. You will have to compile
the C++ code into a DLL and then have the Delphi code use that instead.
Post by James5950
On BCB2007 I know add header file to another unit, but
how to add header file for delphi unit?
There is no such thing as header files in Delphi.


Gambit
Loading...