6

I'm pretty new to Delphi and I'm trying to use the DEHL Collections library. (see http://code.google.com/p/delphi-coll/ ) I'm have a little trouble with it from the IDE perspective. It compiles and runs correctly, but Delphi XE shows errors anywhere I use the HashSet library. The biggest grievance is that is prevents me from using code completion.

The first location I get the error is in an object declaration:

uses
  SysUtils, Windows, Collections.Base, Collections.Sets, Collections.Lists,
  adscnnct, adstable,
  uOtherClass;

type
  OneClass = class(OtherClass)
    private
      _bad: THashSet<string>;   // THashSet underlined
      _good: TList<string>;     // No problems
  end;

The error states: "Type arguments do not match constraints"

I don't think it's configuration as I can use TList just fine, but here is how I set it up: I've copied the library to Projects/Libs/DeHLCollections/Library and compiled the library to Projects/Libs/bin. I've included the bin directory in my global library path, which got it to compile and run. I have tried adding everything (/libs, /DeHLCollections, /Library) to it as well in hopes of getting the IDE to help me out, but it doesn't seem to be helping.

Anyway to fix this, or do I just have to deal with it?

Using DeHL Collections version 1.1.1.119

Eric G
  • 3,427
  • 5
  • 28
  • 52
  • 4
    Let me also say that Generics are not WHERE YOU START as a new delphi programmer. That's like starting on writing DCOM servers on your second day as a Windows C++ programmer. – Warren P Jul 19 '11 at 23:51
  • 2
    You might want to start by learning and observing the idiomatic Delphi practice of naming classes so they start with T and private or protected fields so they start with F, and using CamelCasingLikeThisBecauseItsADelphiReligion. (TOneClass, not OneClass, and field name FBad not field _bad). – Warren P Jul 20 '11 at 02:17
  • @Warren - Thanks for the heads up on a couple of the practices. I guess I bring a few over from using java and php. Can I ask what the T for classes means? T for fields makes sense. Anywhere I can look for standard delphi conventions like these? Also, started with generics may be a little quick, but what's a guy who needs to keep a set supposed to do? In this case it is just strings, so if there is another approach, I'm open to suggestions. I'm just doing it the way I'm used to. – Eric G Jul 20 '11 at 18:52
  • I guess specifically I was wondering if there are any conventions like that for properties? Maybe I should open a new question for this? – Eric G Jul 20 '11 at 19:16
  • 1
    No need to ask a duplicate question. Just read this: http://stackoverflow.com/questions/262892/what-delphi-coding-standards-documents-do-you-follow ... F is for Field, T is for Type (TMyClass and FMyField:TMyClass) – Warren P Jul 20 '11 at 20:12
  • New link, https://github.com/pavkam/DeHL – LU RD Jun 20 '14 at 14:14

1 Answers1

6

Welcome to the troubles with using Generics laden code. DeHL and generics work a lot better in Delphi XE than in any previous Delphi version, but that's not the same as it "not having any problems". The problems I experience are exactly like yours.

My opinion is that DeHL shows every sign of having been written by a master delphi programmer, and that it's a thing of beauty, in some ways. It's also a source of great pain, through no fault of its own.

Delphi contains not one or two, but at least three (maybe four?) separate parsers, including the full compiler parser, and a few IDE-parsers used for things like Error Insight (the errors you see even before you build) and the code completion data parser. Each has different language support limitations with regards to generics. It is possible perhaps that DeHL could be written to avoid parser problems with all the various Delphi parsers. I have not seen a guide ever written that shows the limitations, but I wouldn't be surprised if complex type declarations in the form TSomething<TSomething<ISomethingElse>,TBar<IFoo>> breaks more than a few of those parsers.

If you intend to use Generics very heavily, you may as well turn off Code Completion and Error Insight. You might also want to save often, and be prepared to experience a lot of compiler problems. And don't try to compile generics-heavy code and put it in packages either. I have experienced a lot of URW and AV (internal compiler faults) when I write generics based code. I find that the Delphi compiler team is great at fixing whatever gets reported, but that the Generics are really most stable for me when I restrict myself to using the Generics.Collections that come with Delphi, and not using other generics based code. It seems it is possible to write stuff using the generics features, that the IDE and two-way tools, and code-completion is not yet fully ready to handle. That means, phenomenal cosmic Generic powers come at a cost to the classic RAD IDE productivity features.

That being said, the latest DeHL sources from Subversion work fine for me and build and run with no errors, but the most recent source ZIP of the entire DeHL collection had problems for me.

I expect that over the next few releases of Delphi, whatever issues have been found (and DeHL seems to be a great place to push the boundaries, and that's one of the reasons i'm a big fan of it) will be fixed, and you won't be wondering why heavy-generics break your IDE features, because they'll all be working again.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • I tried the repository, but the HashSet still has issues for me. Everything else works fine, it compiles and runs as expected. So the answer is just gonna be deal with it? – Eric G Jul 20 '11 at 19:07
  • Your remaining issue is purely cosmetic. Turn off Error Insight if you like, but as a newbie, you'd be better leaving the Generics out and leaving Error Insight on. – Warren P Jul 20 '11 at 20:14
  • I lied! It is working now! I don't know if it was restarting the IDE or what, but it's all good now. The SVN repo copy did the trick. – Eric G Jul 20 '11 at 20:26
  • Fabulous. Did you also modify your library paths and browsing paths? – Warren P Jul 20 '11 at 22:58