473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Converting Delphi code

Hello,
I looking for different ideas on how to convert this delphi code to c#,
mostly the constant array.

procedure PhysDmgSymbol(sym : string; yr: integer);
type
d = record
s : String;
r : array[1..4] of double;
end;

const a1 : array[0..19]of d = ((s:'01';r:(1.55,1.18,1.55,1.18)),
(s:'02';r:(1.55,1.18,2.15,1.50)),
(s:'03';r:(1.55,1.18,2.85,1.60)),
(s:'04';r:(1.55,1.18,2.95,1.70)),
(s:'05';r:(1.55,1.18,3.40,1.80)),
(s:'06';r:(1.55,1.18,3.60,1.95)),
(s:'07';r:(2.15,1.50,3.90,2.00)),
(s:'08';r:(2.85,1.60,4.20,2.10)),
(s:'10';r:(3.51,1.80,4.90,2.20)),
(s:'11';r:(3.90,2.00,5.20,2.30)),
(s:'12';r:(4.90,2.20,5.80,2.40)),
(s:'13';r:(5.80,2.40,6.00,2.50)),
(s:'14';r:(6.60,2.80,6.60,2.80)),
(s:'15';r:(7.60,3.15,7.00,3.00)),
(s:'16';r:(9.00,3.40,7.60,3.15)),
(s:'17';r:(10.30,4.40,8.00,3.30)),
(s:'18';r:(0.00,0.00,9.00,3.40)),
(s:'19';r:(0.00,0.00,9.70,3.60)),
(s:'20';r:(0.00,0.00,10.30,4.60)),
(s:'21';r:(0.00,0.00,10.90,4.60)));
var
i : integer;
begin
for i := low(a1) to high(a1) do
begin
if sym = a1[i].s then
begin
nCompFactor := ifthen(yr > 1989,a1[i].r[3],a1[i].r[1]);
nCollFactor := ifthen(yr > 1989,a1[i].r[4],a1[i].r[2]);
exit;
end;
end;

end;
Thanks
Mel

May 31 '06 #1
2 3794
Mel,
I looking for different ideas on how to convert this delphi code to c#,
mostly the constant array.

const a1 : array[0..19]of d = ((s:'01';r:(1.55,1.18,1.55,1.18)),

(s:'02';r:(1.55,1.18,2.15,1.50)),
...


What you need here is a C# struct to match the Delphi record, and a public
constructor for the struct, like this:

------------------
public struct d
{
public string s;
public double[] r;

public d(string s, double[] r)
{
this.s = s;
this.r = r;
}
}
------------------

Next, you can declare a readonly field as an array of "d" inside your C#
class. The trick is to remember to call the constructor of the struct "d",
passing in the parameters. Like this:

------------------
public class TestCSharp
{
private readonly d[] a1 = {
new d("01", new double[] {1.55, 1.18, 1.55, 1.18}),
new d("02", new double[] {1.55, 1.18, 2.15, 1.50})
// etc...
};
}
------------------

That should do it. Two general suggestions for the conversion:

- use better and longer variable names, "d" or "a1" are not very describing
- get rid of "macro like" function like "ifthen", convert these to proper if
statements instead

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
May 31 '06 #2
Mel
Thank You

Mel

"Jani Järvinen [MVP]" <ja***@removethis.dystopia.fi> wrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
Mel,
I looking for different ideas on how to convert this delphi code to c#,
mostly the constant array.

const a1 : array[0..19]of d = ((s:'01';r:(1.55,1.18,1.55,1.18)),

(s:'02';r:(1.55,1.18,2.15,1.50)),
...


What you need here is a C# struct to match the Delphi record, and a public
constructor for the struct, like this:

------------------
public struct d
{
public string s;
public double[] r;

public d(string s, double[] r)
{
this.s = s;
this.r = r;
}
}
------------------

Next, you can declare a readonly field as an array of "d" inside your C#
class. The trick is to remember to call the constructor of the struct "d",
passing in the parameters. Like this:

------------------
public class TestCSharp
{
private readonly d[] a1 = {
new d("01", new double[] {1.55, 1.18, 1.55, 1.18}),
new d("02", new double[] {1.55, 1.18, 2.15, 1.50})
// etc...
};
}
------------------

That should do it. Two general suggestions for the conversion:

- use better and longer variable names, "d" or "a1" are not very
describing
- get rid of "macro like" function like "ifthen", convert these to proper
if statements instead

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

May 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Erva | last post by:
Hi, Is there someone who has moved from Delphi to VS.NET? I'am using Delphi currently but seriously considering to moving VS.NET. I would like to hear if someone has already done that, is it...
25
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
0
by: Islamegy | last post by:
In my C# project.. I have Sql Database with data of 700 MB... I'm redesign tables and relations and need to retrieve my data in the new tables.. I'm using SqlAdapter to Get old tables in my...
7
by: Bart Roozendaal | last post by:
I am using a C# assembly in Delphi.Win32 using the com interop services. This works fine, but I am looking for a way to debug the C# assembly. When using a Delphi program as a host for the...
8
by: Todd Jaspers | last post by:
Hey guys, I've written a fairly simple Windows C# Application using Visual Studio 2005. I have to manually run it, but I would prefer to have it run on it's own, as if it was a Windows NT...
14
by: ApexData | last post by:
I am considering building some distributable commercial applications. For about a year now, I have been using Access2000. This was my first venture into object oriented database development. ...
1
by: Thomas Due | last post by:
Hi, I manage an rather old application in which we have some fairly complex (ugly) Delphi code. This is Delphi 6 we're talking about. Among all this Delphi code there is method for formating a...
4
by: =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?= | last post by:
Dear List, We have a large application written in Delphi. I am writing a mobile app written in .NET (C#) which reads and writes into the Delphi applications Oracle database via a .NET Web...
11
by: gnuist006 | last post by:
Is there a Delphi equivalent in the C world or Scheme/LISP world ? Recently, Delphi is in resurgence. In Russia people are using like crazy. For example, Bolega has written a free image...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.