Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 84579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:57:12+00:00 2026-05-10T21:57:12+00:00

A little example TTest<T> = class private f : T; public function ToString :

  • 0

A little example

TTest<T> = class private   f : T; public   function ToString : string; end; 

If is an object then this should work

TTest<T>.ToString; begin   Result := f.ToString; end; 

But what happens when is say an integer? This would be ok in .net. of course.

I know it won’t work, but how do I code this to work with objects AND simple types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:57:13+00:00Added an answer on May 10, 2026 at 9:57 pm

    There are three reasons why Delphi doesn’t let you do what you are trying to do in your second example – call the ToString method on a value of an unconstrained type parameter type (or at least that’s what I think you were trying to show, since TObject.ToString is an instance method, not a class method, so T.ToString would not work even for TObject).

    1. Delphi does not have a rooted type system, and there are very few operations that are common to all types. These operations – copying, assignment, creating locations (fields, locals, parameters, arrays) – are the only operations that are guaranteed to be available on all possible values of the type parameter.

    2. Following on from 1, why are the operations restricted to these? Why not permit the operations in the generic class, and only give errors at instantiation time? Well, the first part of the reason is that the design was originally intended to maximize compatibility with .NET and dccil, so things that .NET generics did not permit did not have significant affordances in the Win32 generics design.

    3. The second justification for the design is that check-only-at-instantiation-time is problematic. The most famous parametric polymorphism implementation that uses this approach is C++ templates, and it is also famous for its cryptic error messages, as you e.g. try to pass the wrong kind of iterator to an algorithm, and get odd complaints about overloaded operators not being found. The deeper the polymorphism, the worse the problem. In fact, it’s so bad that C++ is itself rectifying this fault in the form of C++ 0x Concepts.

    Hopefully you now understand why operations that aren’t guaranteed to be available via constraints cannot be used. However, you can get out of this restriction relatively easily, by providing the operation in the form of a method reference or interface implementation, as Gamecat suggested.

    In the future, generics in Delphi for Win32 will likely be extended along similar lines to C++ 0x Concepts, or Haskell type classes, such that type parameters may be constrained to have certain methods, functions and operators available. If it went along type class lines, then type inference may proceed in that fashion too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer By coincidence I find out the solution. It is hidden… May 11, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer You have to subclass the UITabBarController and implement custom drawing.… May 11, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer I would use DirectShow to capture the audio. Since you… May 11, 2026 at 5:06 pm

Related Questions

I can't quite figure out this syntax problem with a case expression in a
I'm having a little bit of trouble understanding what the problem is here. I
[resolved] I tweaked the preferences in komodo edit and ended up with: don't auto
How would I go about using a negative lookbehind(or any other method) regular expression

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.