Here
https://wiki.freepascal.org/FPC_PasCocoaand here
https://wiki.freepascal.org/FPC_PasCocoa/Differences#Marking_methods_as_overrideLong story:
1)
The reason is that the Apple API does not give different names...
I like this naming better of course but I feel I am left a bit guessing on the innerworkings of FPC/ObjectivePascal.
Apple API gives different names. As a matter of fact, it HAS to.
In Objective-C the name of the method is also an "address" of the method aka "SELECTOR".
Thus it's impossible in ObjC to do a method overloading, similar to Pascal manner.
Here's an example;
procedure foo(a: Integer); overload;
procedure foo(d: double); overload;
It's perfectly normal way of overloading in pascal. (behind the scenes, the compiler will distinguish between to procedures, by giving them a symbol names, like:
FOO_INT
FOO_DOUBLE.
In ObjC, the declaration of the method, also dictates its name:
void foo:(int) a
However, the name will not contain type information, but also a presence of an parameter.
So the "selector" for the method will be "foo:"
For this particular reason an attempt to declare overloaded method:
void foo:(double) a
will fail (or get runtime confused), as the selector is identical "foo:"
As a result, the actual "names" (selectors) in Apples are pretty long:
- (void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data;
selectors is "connection:didReceiveData:".
But, due to ObjC syntax, calling a method and passing parameters are somewhat mixed, and makes the code look compact.
[obj connection: conn didReceiveData: data]
unlike similar call in pascal (type out the name first and then entire list of parameters)
connection_didReceiveData(conn, data);
2)
Now, when dealing with Objective Pascal, the FPC compiler needs to what ObjC selector needs to be called for each method.
The FPC CANNOT use the pascal "part" of the declaration.
It cannot automatically translated
procedure connection(ANSUC: NSURLConnection;
didSendBodyData: Integer;
totalBytesWritten: Integer;
totalBytesExpectedToWrite: Integer
)
into a selected, for the following reasons:
1) Pascal is case insensitive, while ObjC is.
2) The name of the parameter is pascal is meaningless for the call (and so it can be later changed). While in ObjC it should "matter".
3) ...and others, which i don't remember...
For this particular reason a special keyword "message" is used in Objective Pascal. (the "keyword" was introduced in Delphi for a somewhat similar task in Windows event handling".
the keyword "message" specifies the exact ObjC selector that needs to be called.
That helps to make "Pascal syntax declaration" to be independent of ObjC.
Thus you can help a somewhat friendly pascal name for you method
procedure dataBytesWritten(ANSUC: NSURLConnection;
bytesWritten: Integer;
totalBytesWritten: Integer;
totalBytesExpectedToWrite: Integer
); message 'connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:'
instead of
procedure connection_didSendBodyData_totalBytesWritten_totalBytesExpectedToWrite(ANSUC: NSURLConnection;
bytesWritten: Integer;
totalBytesWritten: Integer;
totalBytesExpectedToWrite: Integer
); message 'connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:'
or naming everything "connection"
3)
Can I ask what you would translate
procedure connection(ANSUC: NSURLConnection;
didSendBodyData: Integer;
totalBytesWritten: Integer;
totalBytesExpectedToWrite: Integer
); message 'connection::::';
You need to refer to Apple documentation for the answer.
The delegate declaration can be found here:
https://developer.apple.com/documentation/foundation/nsurlconnectiondatadelegate?language=objcor more specifically here:
https://developer.apple.com/documentation/foundation/nsurlconnectiondatadelegate/1418264-connection?language=objcThe page actually starts with the selector name: "connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:"
All you need to do, is to put into your pascal declaration as a value of 'message'
procedure connection(ANSUC: NSURLConnection;
didSendBodyData: Integer;
totalBytesWritten: Integer;
totalBytesExpectedToWrite: Integer
); message 'connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:';