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. Follow

10 Replies
1102 Views

Similar Articles

[PageSpeed] 48

> {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:

Similar Artilces:

Delphi 2007 RTL in Delphi 7
I read somewhere that it is possible to use Delphi 2007's (or for that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the source of RTL. Is this really possible? What are the benefits that we can derive using a higher version's RTL? TIA Yogi Yang Yogi Yang wrote: > I read somewhere that it is possible to use Delphi 2007's (or for > that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the > source of RTL. If it actually compiles in Delphi 7, I guess it would be possible. OTOH, if one has Delphi 2007 already, I don't s...

Moving from Delphi 7 to Delphi 2007
Is there any compelling reason to move (quite a large project) from Delphi 7 to Delphi 2007? Specifically, is there better Vista/Win7/Win8 integration provided by Delphi 2007? (In the project I am already using a custom manifest file for Vista/Win7 etc.. and not the std XPMan component) Does 2007 add any new bugs to the scene? Thanks Rael Rael wrote: > Is there any compelling reason to move (quite a large project) from > Delphi 7 to Delphi 2007? If you are going to upgrade, why not upgrade to something newer? > In the project I am already using a custom man...

Delphi 7 to Delphi XE2
Hi, Still using that old workhorse, Delphi7, but am going to the conference in London hosted by Embarcadero on Delphi XE2. Although I would like to "move with the times" and am keen to get the UNICODE and 64-bit support offered by the latest IDEs, I confess to being more than a little scared about all the UNICODE/String/AnsiString and 32/64 bit issues I'm probably going to fall over. Anyone recently upgraded from Delphi7 to one of the latest Delphi IDEs? Thanks, Alain On 03/02/2012 08:55, Alain Dekker wrote: > Still using that old workhorse, Delphi7, but...

Delphi 4 to Delphi 2007
Hello, I will have to port a D4 application (with source) to D2007. what kind of problem could I face ? I will have to go to customer site tommorow to analyse its source code to quote the work, what should I care of to hestimate the porting time ? Thanks John Terry wrote: > Hello, > I will have to port a D4 application (with source) to D2007. > what kind of problem could I face ? > I will have to go to customer site tommorow to analyse its source code > to quote the work, what should I care of to hestimate the porting time ? You can probably do it by just changi...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

DBExpress terrible performance when migrating from Delphi 7 to Delphi 2007
Hi, When I'm migrating my project from Delphi 7 to Delphi 2007, I found that the speed slow down 3-4 times. I've started to investigate what is the reason of that and I've found that the problem is in the TSQLDataset component. So I make a simple example of an application that run one of my problem queries that fetches about 30000 rows and the result was amazing d7: 1500ms, d2007: 13500ms 8 times slower !!!! Here are some perameters of the TSQLConnection Delphi 7: object SQLConn: TSQLConnection ConnectionName = 'OracleConnection' DriverName = '...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

Migrating from Delphi 7 to Delphi XE3
Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. I was wondering if there is a good book or reference to learn all new things XE3 added. Any suggestions? On 5/3/2013 10:17 PM, George Karatsiolis wrote: > Hello, Its time to leave the old Delphi 7 and move to the new (but not the latest) XE3. > I was wondering if there is a good book or reference to learn all new things XE3 added. Try this one for starters: http://tinyurl.com/cgsu243 Aside from that you really need to evaluate your application. XE3 is Unicode for example.... So her...

Delphi 2010 w Delphi 2007
I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). Can I install D2010 on this machine without it affecting D2007? Will D2010 affect D2007 in any way? Thanks, Randall Carpenter > {quote:title=Randall Carpenter wrote:}{quote} > I have D2007 installed on my laptop (XP sp3 running on dual core Athlon). > Can I install D2010 on this machine without it affecting D2007? Will D2010 > affect D2007 in any way? Won't hurt a thing. I have D7, RAD Studio 2007, RAD Studio 2009, and RAD Studio 2010 all on my desktop system and they coexist fine. Jus...

Migrating From Delphi 7 to Delphi 2010
We did not know which forum was the best for this question. We have been wanting to migrate from Delphi 7 to a later version for years but it appears to be a daunting task. We first looked at D2006 and that was a radical new world. We bought D2010 a couple of years ago and not done much with it because there are so many parts to our applications. We have done a few new applications in D2010 and they seem to work okay. D2010 has not been impressive, perhaps because of the strangeness compared to D7. Is is possible for us to do a phased sort of migration where we do a form at a time? ...

Delphi 7 to Delphi 2009 conversion
Hello group, What do I need to do to comile the following code in D2009. Compiler error after the Else E2010: Incompatible Types 'AnsiChar' and 'Char' if isUnicode then SearchHandle := FindFirstFilew( PWideChar( fn ), FindDataW ) else SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ), FindDataA ); <<<<<compiler error in the above line >>>>>>>>>>> Regards, Bryan > What do I need to do to comile the following code in D2009. > Compiler error after the Else > E2010: Incompati...

is there a Delphi 2007
Would be nice to have a bundle of the latest Delphi packages. Gilbert Padilla wrote: > Would be nice to have a bundle of the latest Delphi packages. > I expect Delphi 2007 will only be on sale until the full RAD Studio 2009 edition is published, including Delphi 2009.net. W ...

Delphi 2009 alongside Delphi 2007
Hi all, I am about to install Delphi 2009 on the same development system as Delphi 2007, before I embark is there anything I should be aware of so as to not break my Delphi 2007 installation and projects ? Thanks JT John Taylor wrote: > Hi all, > > I am about to install Delphi 2009 on the same development system > as Delphi 2007, before I embark is there anything I should be aware > of so as to not break my Delphi 2007 installation and projects ? As long as you install into a separate folder there is no problem with the two versions getting into each other...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...