Delphi 2007 to Delphi 7

I've written a class in Delphi 2007 that is not supported in Delphi 7.  What 
would be the best way to achive what I've done in Delphi 2007 in Delphi 7?

Thanks,
Tom

  type  BondConstants = class

    { Bond Types }
    type  BondType = record
      const
         TREASURY = 3;
         AGENCY = 0;
         CORP = 1;
         MUNI = 2;
         SBA = 5;
         MBS = 4;
         CMO = 6;
    end;

    { Day Count Methods }
    type  DayCount = record
      const
        ACTUAL_360 = 2;
        ACTUAL_365 = 1;
        ACTUAL_ACTUAL = 1;
        d30_360 = 0;
    end;

  end;
0
Tom
10/30/2009 2:56:28 PM
📁 embarcadero.delphi.general
📃 4258 articles.
⭐ 0 followers.

💬 10 Replies
👁️‍🗨️ 3287 Views

> {quote:title=Tom Woods wrote:}{quote}
> I've written a class in Delphi 2007 that is not supported in Delphi 7.  What 
> would be the best way to achive what I've done in Delphi 2007 in Delphi 7?
> 
> Thanks,
> Tom
> 
>   type  BondConstants = class
> 
>     { Bond Types }
>     type  BondType = record
>       const
>          TREASURY = 3;
>          AGENCY = 0;
>          CORP = 1;
>          MUNI = 2;
>          SBA = 5;
>          MBS = 4;
>          CMO = 6;
>     end;

That makes absolutely no sense. If you need an enumerated type, use an enumerated type. That's not the proper use of a record (which is used for reading and writing data).

{code}
// The following maintains the original ordinal (numeric) values your code did.
type 
  TBondType = (btAgency, btCorp, btMuni, btTreasury, btMBS, btSBA, btCMO);
{code}
  

>     { Day Count Methods }
>     type  DayCount = record
>       const
>         ACTUAL_360 = 2;
>         ACTUAL_365 = 1;
>         ACTUAL_ACTUAL = 1;
>         d30_360 = 0;
>     end;

Again, this isn't the proper use of a record. You gain nothing over using plain constants instead:

{code}
const
  ACTUAL_360 = 2;
  ACTUAL_365 = 1;
  ACTUAL_ACTUAL = 1;
  d30_360 = 0;
{code}
0
Ken
10/30/2009 3:11:41 PM
With the classs with types, I was able to do the following which makes 
programming easier.

BondConstants.BondTypes.TREASURY

Anytime I need a constant, but can't remember what it is, I just type 
'BondConstants.' and let the IDE popup my options.

Can anyone think of a better way of achieving this functionality in Delphi 7 
and Delphi 2007?

Thanks,
Tom



<Ken White> wrote in message news:178390@forums.codegear.com...
>> {quote:title=Tom Woods wrote:}{quote}
>> I've written a class in Delphi 2007 that is not supported in Delphi 7. 
>> What
>> would be the best way to achive what I've done in Delphi 2007 in Delphi 
>> 7?
>>
>> Thanks,
>> Tom
>>
>>   type  BondConstants = class
>>
>>     { Bond Types }
>>     type  BondType = record
>>       const
>>          TREASURY = 3;
>>          AGENCY = 0;
>>          CORP = 1;
>>          MUNI = 2;
>>          SBA = 5;
>>          MBS = 4;
>>          CMO = 6;
>>     end;
>
> That makes absolutely no sense. If you need an enumerated type, use an 
> enumerated type. That's not the proper use of a record (which is used for 
> reading and writing data).
>
> {code}
> // The following maintains the original ordinal (numeric) values your code 
> did.
> type
>  TBondType = (btAgency, btCorp, btMuni, btTreasury, btMBS, btSBA, btCMO);
> {code}
>
>
>>     { Day Count Methods }
>>     type  DayCount = record
>>       const
>>         ACTUAL_360 = 2;
>>         ACTUAL_365 = 1;
>>         ACTUAL_ACTUAL = 1;
>>         d30_360 = 0;
>>     end;
>
> Again, this isn't the proper use of a record. You gain nothing over using 
> plain constants instead:
>
> {code}
> const
>  ACTUAL_360 = 2;
>  ACTUAL_365 = 1;
>  ACTUAL_ACTUAL = 1;
>  d30_360 = 0;
> {code}
0
Tom
10/30/2009 3:30:24 PM
Tom


You could just use readonly properties and set their value in the constructor.

Roy Lambert
0
Roy
10/30/2009 4:18:00 PM
> With the classs with types, I was able to do the following which makes 
> programming easier.
>
> BondConstants.BondTypes.TREASURY
>
> Anytime I need a constant, but can't remember what it is, I just type 
> 'BondConstants.' and let the IDE popup my options.

If you really wanted to do the equivalent in D7, you could just
put each set of constants in their own unit - eg:

unit BondTypes

const
       TREASURY = 3;
         AGENCY = 0;
         CORP = 1;
         MUNI = 2;
         SBA = 5;
         MBS = 4;
         CMO = 6;
 end.

etc
Bit of a waste of a unit, but would provide you with code completion.

cheers,

Chris
0
Chris
10/30/2009 7:02:27 PM
> Again, this isn't the proper use of a record. 

Dear oh dear... It gives you scoped constants, so that you don't
clutter up the global scope. I take it you avoid adding methods to any
record type you define too, since this isn't a 'proper' use of a record
by the standards of 1995 either?

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
10/30/2009 7:21:04 PM
> {quote:title=Tom Woods wrote:}{quote}
> 
> BondConstants.BondTypes.TREASURY
> 

I have been using something like this in similar cases:

BondConstants_BondTypes_TREASURY = 3;

Dalija Prasnikar
0
Dalija
10/30/2009 9:39:59 PM
> {quote:title=Chris Rolliston wrote:}{quote}
> Dear oh dear... It gives you scoped constants, so that you don't
> clutter up the global scope. I take it you avoid adding methods to any
> record type you define too, since this isn't a 'proper' use of a record
> by the standards of 1995 either?

You can accomplish the same thing (more clearly, IMO) by using a separate unit to establish the scope (namespace) for the constants.

And yes, I add methods to record types, when there's a reason to do so. I don't see what that has to do with anything, though.
0
Ken
11/2/2009 4:18:39 PM
> You can accomplish the same thing (more clearly, IMO) by using a
> separate unit to establish the scope (namespace) for the constants.

I think of it as defining a 'sub-unit', and to that effect, when I use
the feature, it is typically to define a record type that only contains
constants. Note that defining a separate unit still polutes the global
namespace whenever the unit is used - in contrast, records-as-sub-units
enforce scoping. As I've written before though, I realise they won't be
for everyone...
(http://delphihaven.wordpress.com/2009/08/18/tip-scoped-constants/)
0
Chris
11/2/2009 6:27:20 PM
I'm going with individual constants labeled in a way that I can easily 
search and replace later when I move the Delphi 7 forward.



Thanks for all the comments,



Tom




<Dalija Prasnikar> wrote in message news:178504@forums.codegear.com...
>> {quote:title=Tom Woods wrote:}{quote}
>>
>> BondConstants.BondTypes.TREASURY
>>
>
> I have been using something like this in similar cases:
>
> BondConstants_BondTypes_TREASURY = 3;
>
> Dalija Prasnikar
0
Tom
11/2/2009 9:01:28 PM
Tom Woods wrote:

> With the classs with types, I was able to do the following which
> makes programming easier.
> 
> BondConstants.BondTypes.TREASURY

I agree this is better... But as a workarround, you can define the
constants in an enum with a prefix on all elements, like everyone does.

TBondTypes = (btTresury, btAgency, etc)

Then you type bt and the IDE will filter the options for you. Of course
BondTypes.TREASURY syntax is much³³³³ better, but the prefixed enums
usualy are enough to help me remember the available options
0
Magno
11/4/2009 12:12:33 PM
Reply: