9

It's always been strange that there's never been a Description property on the TService in Delphi's VCL. Even to this day, Delphi XE2 doesn't have it yet. It's such a simple and common thing, that I'm wondering why it's not there.

I know how to create it myself, but my point is I shouldn't have to. I was wondering if there's any technical reason why Description of a service doesn't come built-in to Delphi's VCL? Because it seems so simple for them to implement.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • And I must point out I'm looking for technical reasons, not opinions. – Jerry Dodge Mar 19 '13 at 02:22
  • My guess would be that the technical reason is that no one has decided (or thought of) it being necessary, and that to get more information than that you'd have to ask Borland/CodeGear/Embarcadero. IOW, I don't think anyone here can answer this question. :-) Not downvoting or anything else, just commenting. – Ken White Mar 19 '13 at 02:52
  • @Ken That's what I'm thinking, but I'm also thinking that maybe perhaps Windows has some limitation which the VCL doesn't take into consideration, or something along those lines. – Jerry Dodge Mar 19 '13 at 02:55
  • 1
    Why do you ask here a question that only the decision makers of the Delphi team can answer? IMHO you have to think twice before asking a question when it starts asking _why X is (or is not) in Class/Library/Language/etc._ because you know that only a decision maker can ask _why_. – jachguate Mar 19 '13 at 03:52
  • 1
    Yes, this is ultimately a decision made by the Delphi developers, but I'm looking to see if anyone knows of why this decision was made. – Jerry Dodge Mar 19 '13 at 03:55
  • @jachguate This question: http://stackoverflow.com/questions/15764719/the-local-directive-in-delphi is also asking "why X is in language" and the votes exploded. – Jerry Dodge Apr 03 '13 at 00:44
  • @Jerry, if you read the question again, you'll notice the question is _What does the keyword do exactly?_, but not why it is there. IMHO that's a very different question. – jachguate Apr 03 '13 at 01:58
  • @KenWhite: I have asked Borland/CodeGear/Embarcadero several times over the years to update the `TService` architecture, to no avail. Adding a `Description` property (and other `ChangeServiceConfig2()`-related properties, like Failure Actions) is just the tip of the iceberg in functionality that is vitally missing. For instance, `TService` still utilizes the old `Handler()` callback instead of the newer `HandlerEx()` callback, so there is a lot of newer OS notifications that `TService` simply cannot receive. – Remy Lebeau Apr 16 '13 at 19:30
  • @Jerry: "Why does this keyword exist and what does it do?" is a vastly different question than "Why did they decide not to include this?". The first can be factually answered, the second is speculation unless a member of the VCL/RTL decision making process who was involved in that decision happens by. – Ken White Apr 16 '13 at 19:33
  • 1
    @Remy: I'd guess they didn't think it was as high a priority as FMX or generics or any of the other changes, then, but I don't know why that would be the case. You'd be in a better position to find out than me. :-) – Ken White Apr 16 '13 at 19:34
  • Irrelevant question and should be removed or edited. AFAIK, Stack Overflow is not a curiosity forum where people speculate about reasons that original developers had during the development cycle. The only valuable response is not marked as correct, and just a mere opinion of some other developer is. Everything in this page shows why Stack Overflow policies just don't work in the Delphi arena – Alexandre M Jul 24 '23 at 06:40

2 Answers2

10

Setting it requires ChangeServiceConfig2 API function which was introduced with XP & Win2003, the service class in Delphi was written before that, and for a long time, Windows NT4 and 2000 were the baseline for the Delphi RTL.

Also for some unknown reason, Borland (and successors) have been adverse to using dynamic binding on Windows API functions, preferring either static bindings to DLLs or late but non-optional bindings (don't ask me why, it makes no sense to me), and using the previous function would have required either having Win2003 as minimum version or using dynamic binding.

So I don't think it was a deliberate decision, but is more a consequence of company policy on dynamic bindings and plain old code maintainance neglect/oversight.

Eric Grange
  • 5,931
  • 1
  • 39
  • 61
  • +1 That's exactly what I was expecting to hear, it's not that no one thought to do it, it's that the way it works doesn't naturally support it. – Jerry Dodge Mar 19 '13 at 04:13
  • ...and therefore would require a complete re-write of the `TService` in order to make it possible. – Jerry Dodge May 17 '13 at 01:14
  • @JerryDodge not really, you only need to dynamically (if you want to maintain Win2003 and XP compatibility) bind the function and call it when available. No need to rewrite anything, this is just a bit of extra code and an extra property. – Eric Grange May 17 '13 at 10:01
  • Well I mean Embarcadero isn't going to fix just this without fixing all the other missing holes too. – Jerry Dodge May 17 '13 at 13:51
3

You can use like that.

procedure TMyService.ServiceAfterInstall(Sender: TService);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create(KEY_READ or KEY_WRITE);

  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Name, false) then
    begin
      Reg.WriteString('Description', 'All details you can write to here.');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • "I know how to create it myself, but my point is I shouldn't have to." – Jerry Dodge Apr 26 '21 at 15:11
  • btw, it's not working for me, latest win10, even if i see registry key 'Description' with description is created, in Services i see only the service name, description is empty. – Nihila Feb 03 '22 at 17:45
  • @JerryDodge If your whole point is to understand Borland/CodeGear/Embarcadero reason to have overlooked this, the question should be removed. First, there is no point in "knowing why they haven't introduced this property", second, only people involved in the process can know the actual reason. This answer is the one that should be considered the correct one – Alexandre M Jul 24 '23 at 06:35