Author Topic: Delphi 2 & 3 - INT64  (Read 46001 times)

DanaPaul

  • Posts: 335
Delphi 2 & 3 - INT64
« on: 15 May '03 - 09:23 »
I've posted a Bass 1.8 Delphi header file that supports INT64 function return results for Delphi versions 2 and 3

http://members.aol.com/wtgdana/private/Bass/




fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #1 on: 15 May '03 - 17:17 »
Hello

With Delphi 3:

     {$else USE_64_ASM}  Int64(-1)
     
       error : Undeclared identifier Int64
       Could not compile used unit "Bass.pas"

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #2 on: 15 May '03 - 17:54 »
Fred,

The conditional define for Delphi 3 is incorrect.  Change from...

{$ifdef VER120}
 {$define USE_64_ASM}
{$endif VER120}

To..

{$ifdef VER100}
 {$define USE_64_ASM}
{$endif VER100}
{$ifdef VER110}
 {$define USE_64_ASM}
{$endif VER110}

I've uploaded an updated header file.

Thanks :)

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #3 on: 15 May '03 - 19:12 »
Hi
I have try your new version, it compile but when i load the appliation :

error : Bass DLL entry point not found : Bass_Getversion.

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #4 on: 15 May '03 - 19:37 »
Quote
error : Bass DLL entry point not found : Bass_Getversion


Hmmm... I can't duplicate this error.   :-/

I don't know if this would indicate anything wrong with the DLL version itself or the header file itself, but the error message you quoted has an incorrect function label.  It should be Bass_GetVersion, not Bass_Getversion.  The "V" in Version should be uppercase.  I have no idea why this may have changed during FTP download.  ???

Any suggestions?


fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #5 on: 15 May '03 - 19:52 »
Hi

It was GetVersion, sorry, i have do a mistake.

By the way, with the original bass.pas with comp modification, it works like charm.

I have change :
in Var
 QWORD = longint; ( Ian said to change it with "comp" if using Delphi 3, but it crash, when i do it)
in function :
Function BASS_ChannelBytes2Seconds(handle: DWORD; pos: comp): FLOAT; stdcall;external 'bass.dll' name 'BASS_ChannelBytes2Seconds';


function BASS_ChannelSetPosition(handle: DWORD; pos: comp): BOOL; stdcall; external 'bass.dll' name 'BASS_ChannelSetPosition';

« Last Edit: 15 May '03 - 20:04 by fredvs »

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #6 on: 15 May '03 - 20:37 »

Quote

QWORD = longint; ( Ian said to change it with "comp" if using Delphi 3, but it crash, when i do it)


Understood.  This works because you manually changed the QWORD types in the function parameter lists to "COMP", which is a 64 bit Delphi integer type.  However, changing the generic "QWORD" type to a Delphi 4 byte integer type, instead of "COMP", renders the high 32 bits of these function results inaccessible.  Hence, the reason your app was crashing.

Even with manual editing that got you running, you may find a problem positioning or seeking within large media files, or integer overflow.

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #7 on: 16 May '03 - 00:00 »
Alright, then what is your suggetion, why do i receive the error mesage ?

nb : In your code i have load
DWORD = cardinal;
if i let the {}, i get 'invalide floating point operation ' in my apps.

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #8 on: 16 May '03 - 01:51 »
Quote
nb : In your code i have load
DWORD = cardinal; if i let the {}, i get 'invalide floating point operation ' in my apps.


Neither Cardinal nor DWord (defined as an "integer" in Windows.pas) are floating point types.  The problem with NAN (not-a-number) floating point validation is that the Floating Point Processor doesn't pop an immediate error.  Instead, this "Invalid Floating Point Operation" exception is popped the next time any floating point value (COMP) is processed.  All the more reason for exhaustive manual checking of possible NAN values or using a true 64 bit integer.  Solution?  Check your code.

Regarding the BASS_GetVersion problem you found earlier, you can download another copy of the header file.  I made a small change in the assignment of the untyped (dynamic) Proc pointers.

I have my fingers crossed :)




DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #9 on: 16 May '03 - 02:07 »
Fred,

One more thought...  The Delphi flavor of the AudioEngine unit that comes with Bass has many errors (per chance you are still using it).  Specifically in the local variable type assignments that call position and seek functions in Bass.dll.  

In any event, I would look at these functions first.

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #10 on: 16 May '03 - 12:39 »
Apparently, Delphi places parameters on the stack, not in registers (the norm), when optimization is disabled to accomodate debug mode in the IDE.  I've uploaded an improved version that uses a local constant to retrieve these 64 bit return values.  Delphi 2 and 3 owners might be interested in the new header file.

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #11 on: 16 May '03 - 14:42 »
Sorry DanaPaul but i get Bass DLL entry point not found Bass_GetVersion also with the new bass_18.pas

(: JOBnik! :)

  • Posts: 1080
Re: Delphi 2 & 3 - INT64
« Reply #12 on: 16 May '03 - 16:18 »
Hi ;D

Try: BASS_xxx
and not: Bass_xxx

Have fun!

8) JOBnik! 8)

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #13 on: 16 May '03 - 19:36 »
Fred,

Simple, use LoadBassDll;

I suspect that Delphi 3 automatically initializes global Variables to nil.  If this is the case, this error message would be possible if you already have Bass.dll loaded when the Initialize section for the unit is executed.

Make sure that you call LoadBassDll (or do not include other Bass header files that automatically load Bass.dll in the same project so that the correct load library error message will be displayed).  Dynamic module loading and unloading (LoadModule API) uses a reference counter for mapped module usage. Useful if many controls or windows in your project use Bass.dll and you want the module to unload itself when not in use (I remember apps with a small footprint).
Example...

LoadBassDll  
Try
 {do some stuff here}
Finally
 UnloadBassDll
 end;

In the example above, if another section of your program is using Bass.dll the module will not be unloaded, instead its reference counter will be decremented.
« Last Edit: 16 May '03 - 20:45 by DanaPaul »

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #14 on: 16 May '03 - 21:50 »
Hi DanaPaul

Hi have sent to your email my Bass_D3.pas, perhaps it may help you (and me).

Do i have to change the code of my app to use your Bass.pas ?
(I have more than 50.000 lines, then i m a litle bit afraid)
« Last Edit: 16 May '03 - 21:54 by fredvs »

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #15 on: 17 May '03 - 01:52 »

Quote

Do i have to change the code of my app to use your Bass.pas ? (I have more than 50.000 lines, then i m a litle bit afraid)


No, all that you really need is the load library call, LoadBassDll.  Other conventions remain the same, Bass_Init, Bass_GetVersion, etc.

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #16 on: 17 May '03 - 03:18 »
Hello.

Not very well understand...

I do nothing before BASS_GetVersion() (it is in formcreate).

The only thing is that i use bass in the "uses" sector...

And i dont understand why my bass_D3.pas works so good... ::)
« Last Edit: 17 May '03 - 03:22 by fredvs »

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #17 on: 17 May '03 - 04:08 »

Quote

I do nothing before BASS_GetVersion() (it is in formcreate).
The only thing is that i use bass in the "uses" sector...


The only change from above would be to add one line before BASS_GetVersion....

BassDllLoad
BASS_GetVersion()

Quote

And i dont understand why my bass_D3.pas works so good... ::)


It works because you truncated all 64 bit return values to 32 bits, and massaged the parameter lists.  If it ain't broke don't fix it, right Fred? :)

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #18 on: 17 May '03 - 12:37 »
Hi DanaPaul.

With BassDllLoad ;

I get "Undeclared identifier : "BassDllLoad" error.

In your bass.pas, what append with  DWORD = cardinal ?

You have cote it {}, perhaps there is the problem...

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #19 on: 17 May '03 - 13:34 »

Quote

With BassDllLoad ; I get "Undeclared identifier : "BassDllLoad" error.


You need "Bass_18" in your unit uses clause.

Quote

In your bass.pas, what append with  DWORD = cardinal ?
You have cote it {}, perhaps there is the problem...


Not likely.  You can restore the type assignment by removing the brackets {}



fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #20 on: 17 May '03 - 14:29 »
Hi DanaPaul.

OK, it compile, i dont have error message anymore, the program works (i must deep try it) but when i close the app, first i do a bass_free and i get a error message "Handle is invalid" then, after (application.terminate) it crash.

I have try to use your unloadbassdll function, but the same occurs.

I m shure you get the answer.

Bye the way, bravo, great work, it functionates, and now i will test all the functions. (Have you try it with MixK that use the original bass.pas, i dont have find any problems, but i trust you, bass.pas with only comp variable could generate error, but it never occurs with me at the moment... ?)

NB It was not so easy to transform it for bass2.pas to use for bass2.dll (for multiple sound cards), but ok, i have done it and it seems to work too (without application.terminate of course)...
« Last Edit: 17 May '03 - 17:08 by fredvs »

DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #21 on: 17 May '03 - 17:28 »

Quote

when i close the app, first i do a bass_free and i get a error message "Handle is invalid" then, after (application.terminate) it crash.

I have try to use your unloadbassdll function, but the same occurs.


You don't need to call BASS_Free nor UnloadBassDll.  This has already been taken care of in the Bass_18.pas header file.

Neither of these functions are necessary, nor advised in any "Application.OnTerminate" event nor "Finalization" unit section.

One of the problems with static library linking is that the order of libraries loaded during exe launch depends on the order of unit placement in your application.  You have little control over whether BassWMA.dll is loaded before Bass.dll or visa versa.

The same holds true for the order in which Finalization sections in your units are called.  You have little control whether the Finalization section in Bass_18.pas is called before (or after) BassWMA.pas.

An effective solution is to dynamically load libraries and manually code library loading in objects.  Example...

Form.OnShow
 BassDllLoad
 BASS_Init
 BassWMADllLoad
 end

Form.Destroy
 UnloadBassWMADll
 BASS_Free
 UnloadBassDll
 end

I have posted a BassWMA.pas header file that dynamically loads BassWMA.dll just as Bass_18.pas loads Bass.dll.

While at the site, please download a fresh copy of Bass_18.pas.  It already has your DWORD Cardinal type assignment restored and a couple other minor improvements.


fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #22 on: 17 May '03 - 17:46 »
Hi Dana,

It seems to work well but i have problem with bass2.dll (the second card).
When i load :

BASS2_ChannelSetPosition ;
 
I get a BASS2_ERROR_POSITION : raise EBass2Exception.Create(sSeekPositionIllegal);

I dont undrstand why ?



DanaPaul

  • Posts: 335
Re: Delphi 2 & 3 - INT64
« Reply #23 on: 17 May '03 - 18:02 »
It has been my experience that Bass.dll will return this error when trying to seek past the end of a file.  You could ignore this error message by trapping the Exception, or test for seek near end of file before calling the function.

fredvs

  • Posts: 325
Re: Delphi 2 & 3 - INT64
« Reply #24 on: 17 May '03 - 18:51 »
Thanks, but why now, i never get error, do you add that ?

Help me also how to terminate my app.

Imposible to call bass_free, i get a "illegal handle error".

Also imposible to terminate without error message (i try application.terminate, form.close, ...  always the same result...)
« Last Edit: 17 May '03 - 18:54 by fredvs »