-  [WT]  [PS]  [Home] [Manage]

[Return]
Posting mode: Reply
  1.   (reply to 5735)
  2. (for post and file deletion)
/pr/ - Programming
  • Supported file types are: GIF, JPG, PNG, WEBM
  • Maximum file size allowed is 10000 KB.
  • Images greater than 200x200 pixels will be thumbnailed.
  • Currently 448 unique user posts. View catalog

  • Blotter updated: 2018-08-24 Show/Hide Show All

Movies & TV 24/7 via Channel7: Web Player, .m3u file. Music via Radio7: Web Player, .m3u file.


Delphi 7 autism. Basement Dwelling Neckbeard 25/04/22(Tue)02:27 No. 5735
5735

File 174528164685.png - (600B , 32x32 , MAINICON.png )

TL;DR: how do I passed nil to an overloaded method that expects a delegate type argument?

Consider:

unit Autism;

interface

uses SysUtils;

type
TMyDelegate = function(Over9000: Integer): Boolean of object;

TMyShittyClass = class
private
FChargingMahLazor: Boolean;
FCallBack: TMyDelegate;
public
constructor Create(LazorStatus: Boolean); overload;
constructor Create(LazorStatus: Boolean; ACallBack: TMyDelegate); overload;
end;

implementation

constructor TMyShittyClass.Create(LazorStatus: Boolean); overload;
begin
Create(LazorStatus, nil);
end;
constructor TMyShittyClass.Create(LazorStatus: Boolean; ACallBack: TMyDelegate); overload;
begin
FChargingMahLazor := LazorStatus;
FCallBack := ACallBack;
end;

end.

This gives you "there is no overloaded version that can be called with these arguments". Because it has to be typed, not just Pointer. But casting it to TMyDelegate does not work either (as in "TMyDelegate(nil)"). I have found a decent workaround and something that is probably going to summon Cthulhu eventually but I'd prefer a good solution.





Delete post []
Password  
Report post
Reason