Generics and constraints in Delphi is still a bit of pain.
A while ago, I needed a factory for threads. It was more convoluted than I meant it to be, so I had a short chat with Stefan Glienke.
He came up with an example similar to the one below. I tore it apart so you can on each line see what the compiler dislikes.
This fails, but was kind of how I wanted it to be:
type
TFactory = record
class function Manufacture<T: TBaseClass, constructor>(parameter definitions): T;
end;
class function Manufacture<T: TBaseClass, constructor>(parameter definitions): T;
begin
Result := T.Create(parameter values);
end;
type
TComponentFactory = class
class function CreateComponent<T: TComponent>(AOwner: TComponent): T; static;
end;
class function TComponentFactory.CreateComponent<T>(AOwner: TComponent): T;
var
ComponentClass: TComponentClass;
Component: TComponent;
begin
ComponentClass := T;
Component := ComponentClass.Create(AOwner); // you can't do `T.Create(AOwner)`
Result := T(Component); // you can't do `Result := ComponentClass.Create(AOwner);`
end;
The usage:
var
Component: TButton;
Owner: TComponent;
begin
Owner := Application.MainForm;
Component := TComponentFactory<TButton>.CreateComponent(Owner);
Component.Parent := Owner;
end;
In the mean time, Spring4D has added the [Archive.is] Spring4D: TActivator record with many CreateInstance methods that allow you to create instances of classes for which you just have type information.
–jeroen
This fails:
type
TFactory = record
class function Manufacture<T: TBaseClass, constructor>(parameter definitions): T;
end;
class function Manufacture<T: TBaseClass, constructor>(parameter definitions): T;
begin
Result := T.Create(parameter values);
end;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
So I’ve been working on a GExperts based solution (because that gave me a nice starting point). It’s not fully done yet, so here are a few things I’ve used:
The streaming mechanism looks for published methods in the RTTI that have a name equal to the event in the stream and a signature matching the event type.The default section by definition has visibility published for anything compiled in $M+ mode (which is enabled for TPersistent and inherits to descendants).
Ubuntu is the only Linux system I had that – after installing a text-mode console setup – gets itself in the below state with only running apt update and apt-get upgrade.
Preparing to unpack .../archives/apt_1.2.19_armhf.deb ...
Failed to stop apt-daily.timer: Connection timed out
See system logs and 'systemctl status apt-daily.timer' for details.
Failed to get load state of apt-daily.timer: Connection timed out
dpkg: warning: subprocess old pre-removal script returned error exit status 1
I could not find meaningful search results for the above thing, nor did systemctl status apt-daily.timer return anything better than
Failed to get properties: Failed to activate service 'org.freedesktop.systemd1': timed out
Heck, it doesn’t even reboot any more (no helpful search results either):
# reboot
Failed to start reboot.target: Failed to activate service 'org.freedesktop.systemd1': timed out
See system logs and 'systemctl status reboot.target' for details.
Failed to open /dev/initctl: No such device or address
Failed to talk to init daemon.
Nor did systemctl status reboot.target return anything better than
Failed to get properties: Failed to activate service 'org.freedesktop.systemd1': timed out
many people use the left-alt key as it as it is more accessible
development tools uses a lot of Alt-Shift based keyboard shortcuts
Windows by default has the Left Alt+Shift shortcut enabled to switch language+keyboard layout combinations
In most countries, Windows by default has more than one language+keyboard combination installed
Windows remembers per application instance which language+keyboard combination is used
every now and then you will get strange characters in only your development tools.
You can change this Windows setting, but be aware that every now and then, various Windows versions will re-enable the Left Alt+Shift even if you have previously disabled it. As of Windows 7 this occurs far less often, but still seems to occur.
Via a private share: If you ever loose your Google Guides level for no apparent reason, still can post reviews, but cannot post to the Google Guides forums, then just mail Google. They can usually fix the situation.
If you use Outlook to check and manage your email, you can easily use it to check your Gmail account as well. You can set up your Gmail account to allow you to synchronize email across multiple machines using email clients instead of a browser.