Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread type MyDateTime = string
Mon, Apr 1 2019 5:27 AMPermanent Link

Matthew Jones

Is there anything that stops me defining one type to be based on another?

Obviously in classes you can do that, but can I say a new type is a string "underneath", while getting the type safety of classes?

(Related obviously to my datetime question, where I'd like to stop random strings getting copied in to my datetime properties).

--

Matthew Jones
Mon, Apr 1 2019 9:50 AMPermanent Link

ooptimum

Matthew,

You may do that, but any string still be assignable to a variable of this new type.
Mon, Apr 1 2019 10:29 AMPermanent Link

Matthew Jones

ooptimum wrote:

> Matthew,
>
> You may do that, but any string still be assignable to a variable of this new type.

Thanks - better than nothing I guess.

--

Matthew Jones
Thu, Apr 4 2019 10:49 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Is there anything that stops me defining one type to be based on another?  >>

No.  As ooptimum points out, you will still be able to assign the base type to any variables/paramters that use the new type.  This is true even if you define a new type instead of a type synonym:

TMyType = type String;

Tim Young
Elevate Software
www.elevatesoft.com
Image