[SOLVED] Incompatible type, Got address of procedure, expected
procedure...
lazarus / 33-macOS - Mac OS X
----------------------------------------------------------------------
Hansaplast · 2019-02-14 11:04
I'm working with Apple's DiskArbitration and translated the .h files
myself (attached), but I am a noob in the matter (just did take a good
look at other examples).
I do keep running into a strange issue, and hopefully somebody sees or
knows what I have been overlooking.
I did consult with Mr. Google, Stack Exchange, this forum, etc, etc.
and have been staring at this for about a week now without finding a
fix.
My environment:
MacOS Mojave 10.14.3, Lazarus 2.1.0 r60408M (SVN), and FPC 3.0.4
x86_64-darwin-cocoa (alpha).
I have defined the following:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i type
DADiskAppearedCallback = procedure( disk: DADiskRef; context:
univptr); cdecl; DADiskDescriptionChangedCallback = procedure( disk:
DADiskRef; keys: CFArrayRef; context: univptr); cdecl;
DADiskDisappearedCallback = procedure( disk: DADiskRef; context:
univptr); cdecl;
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
DARegisterDiskAppearedCallback( session: DASessionRef;
match: CFDictionaryRef;
callback: DADiskAppearedCallback;
context: UnivPtr ); external name
'_DARegisterDiskAppearedCallback'; procedure
DARegisterDiskDescriptionChangedCallback( session: DASessionRef;
match: CFDictionaryRef;
watch: CFArrayRef;
callback:
DADiskDescriptionChangedCallback;
context: UnivPtr ); external name
'_DARegisterDiskDescriptionChangedCallback'; procedure
DARegisterDiskDisappearedCallback( session: DASessionRef;
match: CFDictionaryRef;
callback: DADiskDisappearedCallback;
context: UnivPtr ); external
name '_DARegisterDiskDisappearedCallback';
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
DiskAppeared( disk: DADiskRef; context: univptr); cdecl;begin // Do
something when a disk appearedend; procedure DiskDescriptionChanged(
disk: DADiskRef; keys: CFArrayRef; context: univptr); cdecl;begin //
Do something when a disk description changed (eg. Mount, Unmount,
etc)end; procedure DiskDisappeared( disk: DADiskRef; context:
univptr); cdecl;begin // Do something when a disk disappearedend;
And calling the registration functions as such:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
DARegisterDiskAppearedCallback(daSession,nil,@DiskAppeared,nil); DARe
gisterDiskDescriptionChangedCallback(daSession,nil,nil,@DiskDescriptio
nChanged,nil); DARegisterDiskDisappearedCallback(daSession,nil,@DiskD
isappeared,nil);
The DiskAppeared and DiskDisappeared work perfectly fine, even using
the context parameter works as expected. I tested this by temporary
commenting out the DARegisterDiskDescriptionChangedCallback call.
However when uncommenting that 3rd registration line
(DARegisterDiskDisappearedCallback), the compiler throws an error:
Code: [Select](line 3 in this example)
Error: Incompatible type for arg no. 4: Got "
", expected ""
DiskArbitration.pas(483,11) Hint: Found declaration: DARegisterDiskDes
criptionChangedCallback(DASessionRef;CFDictionaryRef;CFArrayRef;DADisk
DescriptionChangedCallback;Pointer);
Note:
If I change the DARegisterDiskDescriptionChangedCallback and
DADiskDescriptionChangedCallback definition, by removing the keys:
CFArrayRef;, like shown below, everything compiles fine and actually
works - obviously this is completely wrong (the missing parameter) and
as expected it will throw on a very few occasions an Access Violation
error.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
DADiskDescriptionChangedCallback = procedure( disk: DADiskRef;
context: univptr); cdecl; procedure
DARegisterDiskDescriptionChangedCallback( session: DASessionRef;
match: CFDictionaryRef;
watch: CFArrayRef;
callback:
DADiskDescriptionChangedCallback;
context: UnivPtr ); external name
'_DARegisterDiskDescriptionChangedCallback'; procedure
DiskDescriptionChanged( disk: DADiskRef; context: univptr);
cdecl;begin // Do something when a disk description changed (eg.
Mount, Unmount, etc)end;
Also note that the functions DiskAppeared, DiskDescriptionChanged and
DiskDisappeared are in one and the same unit file, and are not part of
an object or class.
I'm at a loss here trying to find what the problem may be ... does
anyone know what may be wrong here?
I did check for potential double declarations, verified the functions
in the Apple documentation over and over again, etc.
Isn't "procedure(DADiskRef;CFArrayRef;Pointer);CDecl" =
"procedure(DADiskRef;CFArrayRef;Pointer);CDecl" ?
Seems that way with the DiskAppeared and DiskDisappeared calls, yet
doesn't compile with DiskDescriptionChanged.
Why does it work with 2 out of 3 times?
----------------------------------------------------------------------
Thaddy · 2019-02-14 11:41
It is rather simple I guess. Just declare procedure variables like you
did for DADiskDescriptionChangedCallback and pass those instead of
using @, because @ is a pointer type and not a procedure variable.
The compiler tells you exactly that.
----------------------------------------------------------------------
Hansaplast · 2019-02-14 12:41
Thanks for responding Thaddy, and apologies for being inexperienced
with this topic.
Quote from: Thaddy on February 14, 2019, 12:41:06 pmIt is rather
simple I guess. Just declare procedure variables like you did for
DADiskDescriptionChangedCallback and pass those instead of using @,
because @ is a pointer type and not a procedure variable.
The compiler tells you exactly that.
I'm not sure I understand what you mean.
DADiskDescriptionChangedCallback is the one failing.
However it's defined the same way as what I did for the
DADiskAppearedCallback and DADiskDisappearedCallback related code?
I modified my post, since it may not have been obvious that the first
3 lines are types (my bad).
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i type
DADiskAppearedCallback = procedure( disk: DADiskRef; context:
univptr); cdecl; DADiskDescriptionChangedCallback = procedure( disk:
DADiskRef; keys: CFArrayRef; context: univptr); cdecl;
DADiskDisappearedCallback = procedure( disk: DADiskRef; context:
univptr); cdecl;
----------------------------------------------------------------------
Thaddy · 2019-02-14 12:49
The address of (@) should be valid in mode objfpc, but try mode Delphi
for your unit and leave @ out. (Just in case: you do not need mode
macpas… those modes also work on Apple)
If that doesn't work I have to get my mini running again, which is in
the attic at the moment.
----------------------------------------------------------------------
Hansaplast · 2019-02-14 13:05
Thanks Thaddy! That did seem to to the trick - I didn't have to change
the code, just replaced "{$mode objfpc}" with "{$mode delphi}".
It does strike me as weird though that with 2 cases it works just fine
(diskappear and diskdisappear), and a 3rd nearly identical setup
(diskdescriptionchange) fails (in the same unit!). As you can see in
the code: it's all the "same", ...
----------------------------------------------------------------------
Hansaplast · 2019-02-14 13:13
Yeah I was cheering to early ...
So this does cause an Access Violation on some occasions as well, the
exact same when I previously changed the function (intentionally) the
wrong way;
QuoteIf I change the DARegisterDiskDescriptionChangedCallback and
DADiskDescriptionChangedCallback definition, by removing the keys:
CFArrayRef;, like shown below, everything compiles fine and actually
works - obviously this is completely wrong (the missing parameter) and
as expected it will throw on a very few occasions an Access Violation
error.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
DADiskDescriptionChangedCallback = procedure( disk: DADiskRef;
context: univptr); cdecl; procedure
DARegisterDiskDescriptionChangedCallback( session: DASessionRef;
match: CFDictionaryRef;
watch: CFArrayRef;
callback:
DADiskDescriptionChangedCallback;
context: UnivPtr ); external name
'_DARegisterDiskDescriptionChangedCallback'; procedure
DiskDescriptionChanged( disk: DADiskRef; context: univptr);
cdecl;begin // Do something when a disk description changed (eg.
Mount, Unmount, etc)end;
----------------------------------------------------------------------
Cyrax · 2019-02-14 13:40
You need to define calling convention for your registration
procedures, too.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
DARegisterDiskDescriptionChangedCallback( session: DASessionRef;
match: CFDictionaryRef;
watch: CFArrayRef;
callback:
DADiskDescriptionChangedCallback;
context: UnivPtr );cdecl; external name
'_DARegisterDiskDescriptionChangedCallback';
----------------------------------------------------------------------
Hansaplast · 2019-02-14 14:14
Thanks Cyrax for chiming in as well ...
1) When I add "cdecl" as described I get a similar error message (just
the "hint" changed).
Code: [Select]Error: Incompatible type for arg no. 4: Got "", expected ""
Hint: Found declaration: DARegisterDiskDescriptionChangedCallback(DASe
ssionRef;CFDictionaryRef;CFArrayRef;DADiskDescriptionChangedCallback;P
ointer); CDecl;
2) When adding "cdecl ;" to one of the 2 working functions, I get;
Code: [Select]Error: linker: Undefined symbols for architecture
x86_64:
Error: linker: "__DARegisterDiskAppearedCallback", referenced from:
Error: ld: symbol(s) not found for architecture x86_64
(but NOT for DARegisterDiskDescriptionChangedCallback)
It still strikes me as odd that 2 functions work just fine, but the
3rd, declared in the same fashion, totally fails ...
----------------------------------------------------------------------
Thaddy · 2019-02-14 15:53
What is the exact C prototype for those functions? Maybe there is a
const somewhere? That'll save me climbing stairs
I suspect a const * which you should translate as var or as a pointer
to...
----------------------------------------------------------------------
Cyrax · 2019-02-14 17:20
Quote from: Hansaplast on February 14, 2019, 03:14:28 pm
Thanks Cyrax for chiming in as well ...
1) When I add "cdecl" as described I get a similar error message (just
the "hint" changed).
Code: [Select]Error: Incompatible type for arg no. 4: Got "", expected ""
Hint: Found declaration: DARegisterDiskDescriptionChangedCallback(DASe
ssionRef;CFDictionaryRef;CFArrayRef;DADiskDescriptionChangedCallback;P
ointer); CDecl;
2) When adding "cdecl ;" to one of the 2 working functions, I get;
Code: [Select]Error: linker: Undefined symbols for architecture
x86_64:
Error: linker: "__DARegisterDiskAppearedCallback", referenced from:
Error: ld: symbol(s) not found for architecture x86_64
(but NOT for DARegisterDiskDescriptionChangedCallback)
It still strikes me as odd that 2 functions work just fine, but the
3rd, declared in the same fashion, totally fails ...
Remove the underscore from the name definitions. When using cdecl
calling convention, FPC adds the underscore automatically.
----------------------------------------------------------------------
Hansaplast · 2019-02-14 17:28
I'm not seeing any difference between the 3 types and procedures ...
(but I'm not an expert)
The C prototypes (source);
Code: C [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i typedef
void (*DADiskAppearedCallback)(DADiskRef disk, void *context);typedef
void (*DADiskDisappearedCallback)(DADiskRef disk, void
*context);typedef void (*DADiskDescriptionChangedCallback)(DADiskRef
disk, CFArrayRef keys, void *context); extern void
DARegisterDiskAppearedCallback( DASessionRef session,
CFDictionaryRef match,
DADiskAppearedCallback
callback, void *
context ); extern void
DARegisterDiskDisappearedCallback( DASessionRef session,
CFDictionaryRef
match,
DADiskDisappearedCallback callback,
void * context );
extern void
DARegisterDiskDescriptionChangedCallback( DASessionRef
session,
CFDictionaryRef match,
CFArrayRef watch,
DADiskDescriptionChangedCallback callback,
void * context );
----------------------------------------------------------------------
Hansaplast · 2019-02-14 17:36
I'm still confused why 2 of these work fine and one keeps failing ...
@Thaddy:
No need to climb the stairs ... (I do very much appreciate the
help!)
@Cyrax:
I removed the underscore from
"DARegisterDiskDescriptionChangedCallback", and it still produces the
same error. The only way I get it compiled seems to be in Delphi mode
(with or without cdecl and/or underscore).
----------------------------------------------------------------------
Thaddy · 2019-02-14 17:43
void * needs to be a var? Otherwise I have to walk the stairs
----------------------------------------------------------------------
Hansaplast · 2019-02-14 18:06
Not sure, with the other functions using "contect:univptr" for "void *
context" worked fine both ways (set and receive).
I recall seeing something about it being nullable;
Code: C [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i typedef
void ( *DADiskDescriptionChangedCallback )( DADiskRef disk, CFArrayRef
keys, void * __nullable context );
Just tested it; adding "var" in front of the context parameter
actually introduces more access violation messages
----------------------------------------------------------------------
Cyrax · 2019-02-14 19:01
Quote from: Hansaplast on February 14, 2019, 06:36:22 pm
I'm still confused why 2 of these work fine and one keeps failing ...
@Thaddy:
No need to climb the stairs ... (I do very much appreciate the
help!)
@Cyrax:
I removed the underscore from
"DARegisterDiskDescriptionChangedCallback", and it still produces the
same error. The only way I get it compiled seems to be in Delphi mode
(with or without cdecl and/or underscore).
This sounds like a bug at FPC compiler. Have you tried the FPC trunk
or FPC 3.2.x (the next release version, the fixes_3_2 branch)? You can
use fpcupdeluxe to download and install them.
----------------------------------------------------------------------
Cyrax · 2019-02-14 19:09
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i { *
Copyright (c) 1998-2015 Apple Inc. All rights reserved. * *
@APPLE_LICENSE_HEADER_START@ * * This file contains Original Code
and/or Modifications of Original Code * as defined in and that are
subject to the Apple Public Source License * Version 2.0 (the
'License'). You may not use this file except in * compliance with the
License. Please obtain a copy of the License at *
http://www.opensource.apple.com/apsl/ and read it before using this *
file. * * The Original Code and all software distributed under the
License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH
WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT
OR NON-INFRINGEMENT. * Please see the License for the specific
language governing rights and * limitations under the License. * *
@APPLE_LICENSE_HEADER_END@ *}{ Initial Pascal Translation for Free
Pascal: Hans Luijten, , May 2018 } //{$ifc
not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}{$mode
macpas}{$packenum 1}{$macro on}{$inline on}{$calling mwpascal} unit
DADissenter;...
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i { *
Copyright (c) 1998-2015 Apple Inc. All Rights Reserved. * *
@APPLE_LICENSE_HEADER_START@ * * This file contains Original Code
and/or Modifications of Original Code * as defined in and that are
subject to the Apple Public Source License * Version 2.0 (the
'License'). You may not use this file except in * compliance with the
License. Please obtain a copy of the License at *
http://www.opensource.apple.com/apsl/ and read it before using this *
file. * * The Original Code and all software distributed under the
License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH
WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT
OR NON-INFRINGEMENT. * Please see the License for the specific
language governing rights and * limitations under the License. * *
@APPLE_LICENSE_HEADER_END@ }{ Initial Pascal Translation for Free
Pascal: Hans Luijten, , May 2018 }{
Version 100}//{$ifc not defined MACOSALLINCLUDE or not
MACOSALLINCLUDE} {$mode macpas} {$packenum 1} {$macro on}
{$inline on} {$calling mwpascal} unit DiskArbitration; ...
Can you try to change {$mode macpas} to {$mode objfpc} and
remove/change {$calling mwpascal} to {$calling cdecl}? I think that
those aren't needed for Mac OS X (the unix version, not earlier
Macintosh (PowerPC) versions).
----------------------------------------------------------------------
Hansaplast · 2019-02-14 21:00
@Cyrax;
Well, I gave your suggestion a try, but then the entire christmas-tree
with error messages pops up, triggered by;
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$ifc
defined CPUPOWERPC and defined CPUI386} {$error Conflicting
initial definitions for CPUPOWERPC and CPUI386}{$endc}
I'll admit I have copied everything between "interface" and "uses"
from other units, and I'm not 100% sure what it all does (besides
checking widget sets, CPU specifics and some mac stuff). Do I really
need really these definitions?
So with that question in mind I just bluntly stripped away most of
those macros.
Added "cdecl;" to each function and removed the underscore after
"external".
Next I added Cyrax's suggestions (use {$mode objfpc} and {$calling
cdecl}).
And I'm back where I started haha ... so with {$mode objfpc} (in my
application units - not in DiskArbitration and DADissenter) it works
-with the occasional Access Violation, and with {$mode objfpc} I get
the same errors as before ...
The headers now look like this (I've attached the files for those
who'd want to see everything):
DiskArbitration;
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$mode
objfpc} {$packenum 1} {$inline on} {$calling cdecl} unit
DiskArbitration; interface uses
MacTypes,DASession,CFBase,CFDictionary, DADisk, CFArray, DADissenter;
and DADissenter:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$mode
objfpc}{$packenum 1}{$inline on}{$calling cdecl} unit
DADissenter;interface uses
MacTypes,DASession,CFBase,CFDictionary,CFString,mach_error;
and the returning error message ...
Code: [Select]cocoa_applepibaker_daclass.pas(211,85) Error:
Incompatible type for arg no. 4: Got "", expected ""
DiskArbitration.pas(279,11) Hint: Found declaration: DARegisterDiskDes
criptionChangedCallback(DASessionRef;CFDictionaryRef;CFArrayRef;DADisk
DescriptionChangedCallback;Pointer); CDecl;
Next; test a newer FPC version.
p.s. am I the only one experiencing issues with the editor for posting
in the forum here? Each time I use backspace until it jumps to the
previous line, the following line becomes microscopical sized font.
All kinds of [ s i z e ] tags appear ... nice for hiding message, but
maybe I'm doing something wrong here?
----------------------------------------------------------------------
Jonas Maebe · 2019-02-14 21:47
Quote from: Cyrax on February 14, 2019, 08:09:13 pm
Can you try to change {$mode macpas} to {$mode objfpc} and
remove/change {$calling mwpascal} to {$calling cdecl}? I think that
those aren't needed for Mac OS X (the unix version, not earlier
Macintosh (PowerPC) versions).
That is incorrect. {$mode macpas} is a syntax mode like any other and
unrelated to the target platform. {$calling mwpascal} is the calling
convention used by Metrowerks Pascal, which is the same as "cdecl"
except that all "const" record parameters are passed by reference.
The script that created those units relies on both that dialect and
the mwpascal calling convention for correctness.
And the solution to the original compilation problem is probably to
change the "cdecl" into "mwpascal" for the callback declarations. The
script probably failed to translate the procvars, and the person who
did it manually probably manually added "cdecl" to them (while there
should be nothing, since the {$calling mwpascal} means they will
automatically get the correct calling convention). I don't know why
the compiler says it expects a cdecl procvar rather than an mwpascal
procvar though.
----------------------------------------------------------------------
Hansaplast · 2019-02-14 22:02
Thanks for chiming in Jonas!
So cdecl for the callbacks should be mwpascal. OK.
Does this apply for the functions themselves as well (eg. replace all
cdecl's with mwpascal)?
For example:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
DARegisterDiskAppearedCallback( session: DASessionRef;
match: CFDictionaryRef;
callback: DADiskAppearedCallback;
context: UnivPtr ); mwpascal; external name
'DARegisterDiskAppearedCallback';
----------------------------------------------------------------------
Hansaplast · 2019-02-14 22:11
Since it feels like I'm running in circles ... I tried using mwpascal
and ended up with ...
Code: [Select]cocoa_applepibaker_daclass.pas(211,85) Error:
Incompatible type for arg no. 4: Got "", expected
""
DiskArbitration.pas(277,11) Hint: Found declaration: DARegisterDiskDes
criptionChangedCallback(DASessionRef;CFDictionaryRef;CFArrayRef;DADisk
DescriptionChangedCallback;Pointer); MWPascal;
Using cdecl for the function resulted in the same error by the way,
just the last mentioning of mwpascal in the error would say cdecl;
Code: [Select]cocoa_applepibaker_daclass.pas(211,85) Error:
Incompatible type for arg no. 4: Got "", expected
""
DiskArbitration.pas(277,11) Hint: Found declaration: DARegisterDiskDes
criptionChangedCallback(DASessionRef;CFDictionaryRef;CFArrayRef;DADisk
DescriptionChangedCallback;Pointer); cdecl;
----------------------------------------------------------------------
Cyrax · 2019-02-14 23:52
Quote from: Jonas Maebe on February 14, 2019, 10:47:57 pmQuote from:
Cyrax on February 14, 2019, 08:09:13 pm
Can you try to change {$mode macpas} to {$mode objfpc} and
remove/change {$calling mwpascal} to {$calling cdecl}? I think that
those aren't needed for Mac OS X (the unix version, not earlier
Macintosh (PowerPC) versions).
That is incorrect. {$mode macpas} is a syntax mode like any other and
unrelated to the target platform. {$calling mwpascal} is the calling
convention used by Metrowerks Pascal, which is the same as "cdecl"
except that all "const" record parameters are passed by reference.
The script that created those units relies on both that dialect and
the mwpascal calling convention for correctness.
And the solution to the original compilation problem is probably to
change the "cdecl" into "mwpascal" for the callback declarations. The
script probably failed to translate the procvars, and the person who
did it manually probably manually added "cdecl" to them (while there
should be nothing, since the {$calling mwpascal} means they will
automatically get the correct calling convention). I don't know why
the compiler says it expects a cdecl procvar rather than an mwpascal
procvar though.
Thanks, Jonas, for clarification!
----------------------------------------------------------------------
Jonas Maebe · 2019-02-15 17:10
Quote from: Hansaplast on February 14, 2019, 11:11:20 pmSince it feels
like I'm running in circles ...
The problem is that you have not posted your test program (at least I
didn't see it), so everyone has to guess how to make it compilable. My
guess is that you are adding MacOSAll to its the uses clause. That
unit simply contains all universal interfaces units (such as MacTypes,
CFBase etc) as include files. This means that it defines the same
types as those individual units.
Your DADissenter and DiskArbitration units contain the individual
units, and hence use the types from those individual units. If your
main program uses MacOSAll, it will use types with the same name from
the MacOSAll unit instead. In Pascal, two structurally equivalent
types are not necessarily compatible, even if they have the same name.
In this case, the solution will be to also use the individual units
from the universal interfaces in your test program instead of
MacOSAll.
----------------------------------------------------------------------
Jonas Maebe · 2019-02-16 08:34
An alternative could also be to replace the uses clause in your DA
units with just "uses MacOSAll" (and the other DA unit if applicable).
----------------------------------------------------------------------
Hansaplast · 2019-02-16 10:25
Hi Jonas,
I'm taking note of your input and am trying to build a small test
application for this - hope to get back today with an example.
----------------------------------------------------------------------
Hansaplast · 2019-02-16 12:31
Thanks Guys!
I think I have "fixed" it - would have not been able to do this with
all the input and suggested you guys provided!
This has been an educational experience.
I have attached an example project, which uses the callbacks for
DiskAppeared, DiskDisappeared and DiskDescriptionChanged.
So when a disk becomes available, or is removed, or is changed
(mount/unmount/volumename/etc), MacOS will use the callbacks to notify
the test application.
For those interested;
the "context" variable can be used to pass a message. For example when
you programmatically eject a disk, you could pass the message "ejected
by me" and on DiskDisappear that message can be found in the context
(default context='').DAVolumePath: When the path of a disk changes
(eg. mount, unmount, change volumename)DAVolumeName: When you rename
a disk(screenshot attached as well)
So to get it to work, I've set;Code: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {$mode
macpas}{$calling mwpascal}
Added the DiskArbitration framework in the DiskArbitration unit -
which I originally had in the application unit itself (is this the
right place?): Code: Pascal [Select][+][-]window.onload =
function(){var x1 = document.getElementById("main_content_section");
if (x1) { var x = document.getElementsByClassName("geshi");for (var i
= 0; i {$linkframework DiskArbitration}
Remove any cdecl/mwpascal from the function definitions, like so;Code:
Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
DARegisterDiskDescriptionChangedCallback( session: DASessionRef;
match: CFDictionaryRef;
watch: CFArrayRef;
callback:
DADiskDescriptionChangedCallback;
context: UnivPtr ); external name
'_DARegisterDiskDescriptionChangedCallback';
Defined the callback functions with mwpascal, like so;Code: Pascal
[Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
DADiskDisappearedCallback = procedure( disk: DADiskRef; context:
univptr); mwpascal;