How to convert Delphi Record to C#?

There is an old program that I'm rewriting. The program stores the
data into an array and dumps it to a file. I can't seem to properly
load the file though.

Here is the record I'm working with:

type
  TMyJob = record
    ReceiveDate: string[10];
    JobName: string[150];
    Contractor: string[100];
    AssignDate: string[10];
    DetailerName: string[30];
end;

Jobs: array of TMyJob;

Does anyone know how to convert this?
0
Magus
3/12/2010 5:37:27 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

14 Replies
1675 Views

Similar Articles

[PageSpeed] 0

"Magus" <mr.magus@gmail.com> wrote in message 
news:c234d4d2-221a-4389-802c-a1eaada8791c@v20g2000yqv.googlegroups.com...
> There is an old program that I'm rewriting. The program stores the
> data into an array and dumps it to a file. I can't seem to properly
> load the file though.
>
> Here is the record I'm working with:
>
> type
>  TMyJob = record
>    ReceiveDate: string[10];
>    JobName: string[150];
>    Contractor: string[100];
>    AssignDate: string[10];
>    DetailerName: string[30];
> end;
>
> Jobs: array of TMyJob;
>
> Does anyone know how to convert this?

You want C# to load this information into a array?

Is that what it looks like inside the file?  In which case, could you give 
an example of a couple of instances of the array inside the file.

You can just use File.ReadAllText() to get the contents, pass it line and 
line and load it up.  I'm sure there is a RegEx way to do it - But I'm not 
RegEx expert myself.

-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com 

0
Mike
3/12/2010 5:45:05 PM
Magus wrote:
> There is an old program that I'm rewriting. The program stores the
> data into an array and dumps it to a file. I can't seem to properly
> load the file though.
> 
> Here is the record I'm working with:
> 
> type
>   TMyJob = record
>     ReceiveDate: string[10];
>     JobName: string[150];
>     Contractor: string[100];
>     AssignDate: string[10];
>     DetailerName: string[30];
> end;
> 
> Jobs: array of TMyJob;
> 
> Does anyone know how to convert this?

That would depend how the contents are streamed to file. Language aside, 
if the "dumping" is done by some custom streamer, it's impossible to know.

It's been a while since I've done any serious work with Delphi (I left 
at D7), but I think the following questions might be of importance:

1) Is the file defined as a "file" variable (i.e. : var myFile: file of 
TMyJob (if memory serves)), or is it some custom streaming mechanism?

2) Are the strings pre- or post unicode? (Unicode strings were 
introduced in what, D2007? D2009?)

If you can provide more info about this, I hope I can be of more help.
Lacking that, I can think of lots of schemes to read the file, but they 
all boil down to manual parsing.

Also, every once in a while, Rudy Velthuis pops up in here, perhaps he 
can chip in. You could also raise the question in the embarcadero 
newsgroups. I don't think the C# Builder newsgroup is very active any 
more, but maybe they still have an appropriate group to post this 
question in.

-- 
   Willem van Rumpt
0
Willem
3/12/2010 6:17:05 PM
On Mar 12, 1:17=A0pm, Willem van Rumpt <noth...@nowhere.com> wrote:
> Magus wrote:
> > There is an old program that I'm rewriting. The program stores the
> > data into an array and dumps it to a file. I can't seem to properly
> > load the file though.
>
> > Here is the record I'm working with:
>
> > type
> > =A0 TMyJob =3D record
> > =A0 =A0 ReceiveDate: string[10];
> > =A0 =A0 JobName: string[150];
> > =A0 =A0 Contractor: string[100];
> > =A0 =A0 AssignDate: string[10];
> > =A0 =A0 DetailerName: string[30];
> > end;
>
> > Jobs: array of TMyJob;
>
> > Does anyone know how to convert this?
>
> That would depend how the contents are streamed to file. Language aside,
> if the "dumping" is done by some custom streamer, it's impossible to know=
..
>
> It's been a while since I've done any serious work with Delphi (I left
> at D7), but I think the following questions might be of importance:
>
> 1) Is the file defined as a "file" variable (i.e. : var myFile: file of
> TMyJob (if memory serves)), or is it some custom streaming mechanism?
>
> 2) Are the strings pre- or post unicode? (Unicode strings were
> introduced in what, D2007? D2009?)
>
> If you can provide more info about this, I hope I can be of more help.
> Lacking that, I can think of lots of schemes to read the file, but they
> all boil down to manual parsing.
>
> Also, every once in a while, Rudy Velthuis pops up in here, perhaps he
> can chip in. You could also raise the question in the embarcadero
> newsgroups. I don't think the C# Builder newsgroup is very active any
> more, but maybe they still have an appropriate group to post this
> question in.
>
> --
> =A0 =A0Willem van Rumpt

Here is the code that saves to array, then to file.

procedure TMainForm.SaveJobsToArray;
var
 i,jobcount: Integer;
begin
//loop through all the Listview items and assign them to the array
  jobcount :=3D ExtListView1.Items.Count;
  SetLength(Jobs,jobcount);
  for i :=3D 0 to jobcount-1 do
    begin
      with ExtListView1.Items[i] do begin
        Jobs[i].ReceiveDate :=3D Caption;
        Jobs[i].JobName :=3D SubItems[0];
        Jobs[i].Contractor :=3D SubItems[1];
        Jobs[i].AssignDate :=3D SubItems[2];
        Jobs[i].DetailerName :=3D SubItems[3];
      end;//with
    end;
end;

procedure TMainForm.SaveJobToFile(filepath: string);
var
  MyJobFile: TRebarJobFile; //file used to store rebar jobs
//  Job: TRebarJob; //structure of file information
  i: integer; //basic loop counters
begin
  SaveJobsToArray;
  try
  System.Assign(MyJobFile,filepath);
  Rewrite(MyJobFile);
  for i :=3D 0 to Length(Jobs)-1 do
    begin
      Write(MyJobFile,Jobs[i]);
    end;
  finally
    System.CloseFile(MyJobFile);
    end;
end;

I did find another article that is almost what I'm needing:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/bro=
wse_thread/thread/95d54b93a0627bd3/10af49c6d09a9fd6?hl=3Den&q=3DConvert+Del=
phi+record+structure+to+C+Sharp#10af49c6d09a9fd6

The problem is that the code doesn't work. Maybe because I'm using a
newer version of C#....
0
Magus
3/12/2010 6:24:03 PM
> Here is the code that saves to array, then to file.
>
> procedure TMainForm.SaveJobsToArray;
> var
> i,jobcount: Integer;
> begin
> //loop through all the Listview items and assign them to the array
>  jobcount := ExtListView1.Items.Count;
>  SetLength(Jobs,jobcount);
>  for i := 0 to jobcount-1 do
>    begin
>      with ExtListView1.Items[i] do begin
>        Jobs[i].ReceiveDate := Caption;
>        Jobs[i].JobName := SubItems[0];
>        Jobs[i].Contractor := SubItems[1];
>        Jobs[i].AssignDate := SubItems[2];
>        Jobs[i].DetailerName := SubItems[3];
>      end;//with
>    end;
> end;
>
> procedure TMainForm.SaveJobToFile(filepath: string);
> var
>  MyJobFile: TRebarJobFile; //file used to store rebar jobs
> //  Job: TRebarJob; //structure of file information
>  i: integer; //basic loop counters
> begin
>  SaveJobsToArray;
>  try
>  System.Assign(MyJobFile,filepath);
>  Rewrite(MyJobFile);
>  for i := 0 to Length(Jobs)-1 do
>    begin
>      Write(MyJobFile,Jobs[i]);
>    end;
>  finally
>    System.CloseFile(MyJobFile);
>    end;
> end;
>
> I did find another article that is almost what I'm needing:
> http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/95d54b93a0627bd3/10af49c6d09a9fd6?hl=en&q=Convert+Delphi+record+structure+to+C+Sharp#10af49c6d09a9fd6
>
> The problem is that the code doesn't work. Maybe because I'm using a
> newer version of C#....

If all the arrays are stored in the same output file, could you post an 
example of the file with a few entries in it?  It's a two minute coding job 
to write something to do this for you.

-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com 

0
Mike
3/12/2010 7:10:15 PM
On Mar 12, 2:10=A0pm, "Mike Lovell" <dont.re...@gotinker.com> wrote:
> > Here is the code that saves to array, then to file.
>
> > procedure TMainForm.SaveJobsToArray;
> > var
> > i,jobcount: Integer;
> > begin
> > //loop through all the Listview items and assign them to the array
> > =A0jobcount :=3D ExtListView1.Items.Count;
> > =A0SetLength(Jobs,jobcount);
> > =A0for i :=3D 0 to jobcount-1 do
> > =A0 =A0begin
> > =A0 =A0 =A0with ExtListView1.Items[i] do begin
> > =A0 =A0 =A0 =A0Jobs[i].ReceiveDate :=3D Caption;
> > =A0 =A0 =A0 =A0Jobs[i].JobName :=3D SubItems[0];
> > =A0 =A0 =A0 =A0Jobs[i].Contractor :=3D SubItems[1];
> > =A0 =A0 =A0 =A0Jobs[i].AssignDate :=3D SubItems[2];
> > =A0 =A0 =A0 =A0Jobs[i].DetailerName :=3D SubItems[3];
> > =A0 =A0 =A0end;//with
> > =A0 =A0end;
> > end;
>
> > procedure TMainForm.SaveJobToFile(filepath: string);
> > var
> > =A0MyJobFile: TRebarJobFile; //file used to store rebar jobs
> > // =A0Job: TRebarJob; //structure of file information
> > =A0i: integer; //basic loop counters
> > begin
> > =A0SaveJobsToArray;
> > =A0try
> > =A0System.Assign(MyJobFile,filepath);
> > =A0Rewrite(MyJobFile);
> > =A0for i :=3D 0 to Length(Jobs)-1 do
> > =A0 =A0begin
> > =A0 =A0 =A0Write(MyJobFile,Jobs[i]);
> > =A0 =A0end;
> > =A0finally
> > =A0 =A0System.CloseFile(MyJobFile);
> > =A0 =A0end;
> > end;
>
> > I did find another article that is almost what I'm needing:
> >http://groups.google.com/group/microsoft.public.dotnet.languages.csha...
>
> > The problem is that the code doesn't work. Maybe because I'm using a
> > newer version of C#....
>
> If all the arrays are stored in the same output file, could you post an
> example of the file with a few entries in it? =A0It's a two minute coding=
 job
> to write something to do this for you.
>
> --
> Mike
> GoTinker, C# Bloghttp://www.gotinker.com

Here is the example:
12/28/2009=1AMINOR LANE PUMPING
STATIONS
=05K C Ctt
Const.
01/05/2010=03Ron
12/28/2009(ST.JOSEPH CATHOLIC CHURCH RESTROOM ADD'N'S
CROSSROADS,NC
=11Sullivan &
Cozart
12/29/2009=03Dony

There are a lot of spaces and characters. Like on the last entry. The
user is "Don" and not "Dony".
0
Magus
3/12/2010 7:46:51 PM
> Here is the example:
> 12/28/2009MINOR LANE PUMPING
> STATIONS
> K C Ctt
> Const.
> 01/05/2010Ron
> 12/28/2009(ST.JOSEPH CATHOLIC CHURCH RESTROOM ADD'N'S
> CROSSROADS,NC
> Sullivan &
> Cozart
> 12/29/2009Dony
>
> There are a lot of spaces and characters. Like on the last entry. The
> user is "Don" and not "Dony".

Hrm, well that could be reading it with the wrong encoding.  But then 
there's going to be a certain binary structure to the file by the looks of 
it.

I think the exact formatting is going to be lost in the news post/reader.

Could you do this, make a file like above with test data using delphi (3 or 
4 records), then from C#:

Console.WriteLine(Convert.ToBase64String(File.ReadAllBytes("filename.ext")));

And post back the output.  That will survive being sent as plaint text

-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com 

0
Mike
3/12/2010 8:00:56 PM
On Mar 12, 3:00=A0pm, "Mike Lovell" <dont.re...@gotinker.com> wrote:
> > Here is the example:
> > 12/28/2009 MINOR LANE PUMPING
> > STATIONS
> > =A0K C Ctt
> > Const.
> > 01/05/2010 Ron
> > 12/28/2009(ST.JOSEPH CATHOLIC CHURCH RESTROOM ADD'N'S
> > CROSSROADS,NC
> > =A0Sullivan &
> > Cozart
> > 12/29/2009 Dony
>
> > There are a lot of spaces and characters. Like on the last entry. The
> > user is "Don" and not "Dony".
>
> Hrm, well that could be reading it with the wrong encoding. =A0But then
> there's going to be a certain binary structure to the file by the looks o=
f
> it.
>
> I think the exact formatting is going to be lost in the news post/reader.
>
> Could you do this, make a file like above with test data using delphi (3 =
or
> 4 records), then from C#:
>
> Console.WriteLine(Convert.ToBase64String(File.ReadAllBytes("filename.ext"=
)));
>
> And post back the output. =A0That will survive being sent as plaint text
>
> --
> Mike
> GoTinker, C# Bloghttp://www.gotinker.com

Ok, here is the output:

CjAzLzEyLzIwMTADQkpLQyBDYXZlaW5nbyAxLDAwMCwwMDAgR0FMLERPTUUgRS02OTQ4IEFEQUl=
SIENPLixLWS4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEkRhdmlkI=
ENvbnN0cnVjdGlvbgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKMDMvMTIvMjAxMANSb25uAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKMDMvMTEvMjAxMAlNVVRDIENhdmVBcGFydG1lbnRzIC=
0gRm9ydCBLbm94bnNhczk4NCBFTEtIQVJULElORCxJTEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAADQU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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABdIdWVsc21h=
bi1Td2VlbmV5IENvbnN0LgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACjAxLzA4LzIwMTADRG9uAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAACjAxLzA1LzIwMTA1Q0FMRFdFTEwgVEFOSyAxLDAwMCwwM=
DAgR0FMLERPTUUgRS02OTQ4IEFEQUlSIENPLixLWS4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAADkNhbGR3ZWxsIFRhbmtzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAKMDEvMDYvMjAxMANEb24AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=3D
0
Magus
3/12/2010 8:26:48 PM
> Ok, here is the output:
>
>  <snip>

BTW/ if I'm right on this you owe me a "telling everyone you know about my 
blog" !!! :op


Your input data?


receiveDate: 03/12/2010
jobName: BJK
contractor: David Construction
assignDate: 03/12/2010
detailerName: Ron

receiveDate: 03/11/2010
jobName: MUTC Cave
contractor: AML
assignDate: 03/11/2010
detailerName: Ron

receiveDate: 03/11/2010
jobName: Steindam Apartments - Fort Knox
contractor: Roederer Construction
assignDate: 03/11/2010
detailerName: Ron

receiveDate: 03/10/2010
jobName: Camp Piomingo
contractor: David Construction
assignDate: 03/10/2010
detailerName: Ron

receiveDate: 03/10/2010
jobName: Caldwell E-6953 Independence Kansas
contractor: Caldwell
assignDate: 03/11/2010
detailerName: Ron

receiveDate: 03/08/2010
jobName: Dollar General English, In
contractor: Sprigler
assignDate: 03/09/2010
detailerName: Ron

receiveDate: 03/05/2010
jobName: Glassworks Garage
contractor: Bosse-Mattingly
assignDate: 03/11/2010
detailerName: Ron

receiveDate: 03/05/2010
jobName: Clay Commons
contractor: Bosse-Mattingly
assignDate: 03/11/2010
detailerName: Ron

receiveDate: 03/04/2010
jobName: Norton Cancer
contractor: Sullivan & Cozart
assignDate: 03/04/2010
detailerName: John

receiveDate: 03/03/2010
jobName: E.W. Brown LG&E
contractor: Kelsey
assignDate: 03/03/2010
detailerName: Ron

receiveDate: 03/02/2010
jobName: Scottsburg TIE Center
contractor: Broughton
assignDate: 03/10/2010
detailerName: John

receiveDate: 03/02/2010
jobName: Ft. Knox
contractor: Kelsey
assignDate: 03/04/2010
detailerName: Ron

receiveDate: 03/01/2010
jobName: Taffel
contractor: E&W
assignDate: 03/01/2010
detailerName: Ron

receiveDate: 03/01/2010
jobName: Wendy's Clarksville, Tn
contractor: Castlewood
assignDate: 03/01/2010
detailerName: Ron

receiveDate: 02/26/2010
jobName: Mammoth Cave
contractor: Howard Pence
assignDate: 03/01/2010
detailerName: Ron

receiveDate: 02/24/2010
jobName: Kohl's
contractor: AML
assignDate: 02/24/2010
detailerName: Ron / John

receiveDate: 02/22/2010
jobName: GENENTECH
contractor: Parco
assignDate: 02/23/2010
detailerName: Ron

receiveDate: 02/19/2010
jobName: E.W.BROWN GYPSUM-MERCER CO.
contractor: Evans Const/Kelsey Const
assignDate: 02/19/2010
detailerName: Ron

receiveDate: 02/17/2010
jobName: CALDWELL TANK 1,000,000 GAL.FDN E-6984 ELKHART,IND
contractor: Caldwell Tanks
assignDate: 02/19/2010
detailerName: Don

receiveDate: 02/16/2010
jobName: DECO-NEW PRESS
contractor: Sullivan & Cozart
assignDate: 02/17/2010
detailerName: Don

receiveDate: 02/08/2010
jobName: CALDWELL TANK 750,000 GAL DOME E-6950 SANGAMON CO.,ILL
contractor: Caldwell Tanks
assignDate: 02/10/2010
detailerName: Don

receiveDate: 01/26/2010
jobName: KY. TRAILER
contractor: Parco
assignDate: 01/26/2010
detailerName: Don

receiveDate: 01/22/2010
jobName: FIELD ELEM.SCHOOL-MECH.VAULT REPAIR
contractor: David Const.
assignDate: 01/25/2010
detailerName: Don

receiveDate: 01/13/2010
jobName: PIOMINGO POOL HOUSE
contractor: David Const.
assignDate: 01/14/2010
detailerName: Ron

receiveDate: 01/11/2010
jobName: KENTUCKY EXPO HORSE BARNS
contractor: Parco
assignDate: 01/11/2010
detailerName: Don

receiveDate: 01/11/2010
jobName: WESTPORT RD. CHURCH of CHRIT
contractor: A M L Construction
assignDate: 01/19/2010
detailerName: Ron

receiveDate: 01/08/2010
jobName: ESSROC MISC.-SELLERSBURG
contractor: Huelsman-Sweeney Const.
assignDate: 01/08/2010
detailerName: Don

receiveDate: 01/05/2010
jobName: CALDWELL TANK 1,000,000 GAL,DOME E-6948 ADAIR CO.,KY.
contractor: Caldwell Tanks
assignDate: 01/06/2010
detailerName: Don


If so, the format was, first byte is the length of the data ... Then you 
read the maximum field length (from your first post).  Then you convert to 
ASCII the result of that (but only convert the length of the data, given by 
the first byte) ... Then repeat...

!!!DISCLAIMER!!!
This code is a 5 minute hack up, it's not my best but it demonstrates what I 
did...


static void Main(string[] args)
{
	var base64		= "<base64 data you posted>";
	var rawData		= Convert.FromBase64String(base64);
	var stream		= new MemoryStream(rawData);

	while (true)
	{
		var receiveDate	= GetBlock(stream, 10);
		var jobName	= GetBlock(stream, 150);
		var contractor = GetBlock(stream, 100);
		var assignDate = GetBlock(stream, 10);
		var detailerName = GetBlock(stream, 30);

		if (detailerName == null) break;

		Console.WriteLine("receiveDate: {0}", receiveDate);
		Console.WriteLine("jobName: {0}", jobName);
		Console.WriteLine("contractor: {0}", contractor);
		Console.WriteLine("assignDate: {0}", assignDate);
		Console.WriteLine("detailerName: {0}", detailerName);

		Console.WriteLine();
	}

	Console.ReadLine();
}


private static string GetBlock(Stream stream, int maxSize)
{
	var buffer		= new byte[maxSize];

	stream.Read(buffer, 0, 1);  // first byte is the size

	var size		= buffer[0];

	var length = stream.Read(buffer, 0, maxSize); // read the entire field 
length

	if (length == 0) return null; // nothing returned

	return Encoding.ASCII.GetString(buffer, 0, size);  // return the ASCII 
string
}



-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com
 

0
Mike
3/12/2010 10:05:41 PM
On 12-03-2010 13:24, Magus wrote:
> On Mar 12, 1:17 pm, Willem van Rumpt<noth...@nowhere.com>  wrote:
>> Magus wrote:
>>> There is an old program that I'm rewriting. The program stores the
>>> data into an array and dumps it to a file. I can't seem to properly
>>> load the file though.
>>
>>> Here is the record I'm working with:
>>
>>> type
>>>    TMyJob = record
>>>      ReceiveDate: string[10];
>>>      JobName: string[150];
>>>      Contractor: string[100];
>>>      AssignDate: string[10];
>>>      DetailerName: string[30];
>>> end;
>>
>>> Jobs: array of TMyJob;
>>
>>> Does anyone know how to convert this?
>>
>> That would depend how the contents are streamed to file. Language aside,
>> if the "dumping" is done by some custom streamer, it's impossible to know.
>>
>> It's been a while since I've done any serious work with Delphi (I left
>> at D7), but I think the following questions might be of importance:
>>
>> 1) Is the file defined as a "file" variable (i.e. : var myFile: file of
>> TMyJob (if memory serves)), or is it some custom streaming mechanism?
>>
>> 2) Are the strings pre- or post unicode? (Unicode strings were
>> introduced in what, D2007? D2009?)
>>
>> If you can provide more info about this, I hope I can be of more help.
>> Lacking that, I can think of lots of schemes to read the file, but they
>> all boil down to manual parsing.
>>
>> Also, every once in a while, Rudy Velthuis pops up in here, perhaps he
>> can chip in. You could also raise the question in the embarcadero
>> newsgroups. I don't think the C# Builder newsgroup is very active any
>> more, but maybe they still have an appropriate group to post this
>> question in.
>>
>> --
>>     Willem van Rumpt
>
> Here is the code that saves to array, then to file.
>
> procedure TMainForm.SaveJobsToArray;
> var
>   i,jobcount: Integer;
> begin
> //loop through all the Listview items and assign them to the array
>    jobcount := ExtListView1.Items.Count;
>    SetLength(Jobs,jobcount);
>    for i := 0 to jobcount-1 do
>      begin
>        with ExtListView1.Items[i] do begin
>          Jobs[i].ReceiveDate := Caption;
>          Jobs[i].JobName := SubItems[0];
>          Jobs[i].Contractor := SubItems[1];
>          Jobs[i].AssignDate := SubItems[2];
>          Jobs[i].DetailerName := SubItems[3];
>        end;//with
>      end;
> end;
>
> procedure TMainForm.SaveJobToFile(filepath: string);
> var
>    MyJobFile: TRebarJobFile; //file used to store rebar jobs
> //  Job: TRebarJob; //structure of file information
>    i: integer; //basic loop counters
> begin
>    SaveJobsToArray;
>    try
>    System.Assign(MyJobFile,filepath);
>    Rewrite(MyJobFile);
>    for i := 0 to Length(Jobs)-1 do
>      begin
>        Write(MyJobFile,Jobs[i]);
>      end;
>    finally
>      System.CloseFile(MyJobFile);
>      end;
> end;
>
> I did find another article that is almost what I'm needing:
> http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/95d54b93a0627bd3/10af49c6d09a9fd6?hl=en&q=Convert+Delphi+record+structure+to+C+Sharp#10af49c6d09a9fd6
>
> The problem is that the code doesn't work. Maybe because I'm using a
> newer version of C#....

I think the idea is correct, but maybe not the implementation.

The following works here with Delphi 7 and .NET 3.5:

program writerecs;

{$APPTYPE CONSOLE}

uses
   SysUtils;

type
   TFooBar = record
      a : string[10];
      b : string[20];
      c : string[30];
   end;

var
   i : integer;
   data : array [1..4] of TFooBar;
   f : file of TFooBar;

begin
   data[1].a := '1a';
   data[1].b := '1b';
   data[1].c := '1c';
   data[2].a := '2a';
   data[2].b := '2b';
   data[2].c := '2c';
   data[3].a := '3a';
   data[3].b := '3b';
   data[3].c := '3c';
   data[4].a := '4a';
   data[4].b := '4b';
   data[4].c := '4c';
   assign(f, 'C:\foobar.dat');
   rewrite(f);
   for i := low(data) to high(data) do begin
     write(f, data[i]);
   end;
   close(f);
   readln;
end.

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace E
{
     [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=1)]
     public struct TFooBar
     {
         private byte alen;
         [MarshalAs(UnmanagedType.ByValTStr,SizeConst=10)]
         public string a;
         private byte blen;
         [MarshalAs(UnmanagedType.ByValTStr,SizeConst=20)]
         public string b;
         private byte clen;
         [MarshalAs(UnmanagedType.ByValTStr,SizeConst=30)]
         public string c;
     }
     public class Program
     {
         public static void Main(string[] args)
         {
             Stream stm = new FileStream(@"C:\foobar.dat", 
FileMode.Open, FileAccess.Read);
             TFooBar[] data = new TFooBar[4];
             int bufsiz = Marshal.SizeOf(typeof(TFooBar));
             byte[] b = new byte[bufsiz];
             IntPtr buf = Marshal.AllocHGlobal(bufsiz);
             for(int i = 0; i < data.Length; i++)
             {
                 stm.Read(b, 0, b.Length);
                 Marshal.Copy(b, 0, buf, b.Length);
                 data[i] = (TFooBar)Marshal.PtrToStructure(buf, 
typeof(TFooBar));
             }
             Marshal.FreeHGlobal(buf);
             stm.Close();
             for(int i = 0; i < data.Length; i++)
             {
                 Console.WriteLine(data[i].a + " " + data[i].b + " " + 
data[i].c);
             }
             Console.ReadKey();
         }
     }
}

Arne



0
ISO
3/13/2010 3:36:22 AM
"Magus" <mr.magus@gmail.com> wrote in message 
news:c234d4d2-221a-4389-802c-a1eaada8791c@v20g2000yqv.googlegroups.com...
> There is an old program that I'm rewriting. The program stores the
> data into an array and dumps it to a file. I can't seem to properly
> load the file though.

Would be good if you could post back if any of the suggestions fixed your 
problem, and if so which.

Will help the community if someone comes across this problem in future.

Thanks,

-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com 

0
Mike
3/14/2010 3:10:06 AM
Magus <mr.magus@gmail.com> wrote:
>
>Here is the example:
>12/28/2009MINOR LANE PUMPING
>STATIONS
>K C Ctt
>Const.
>01/05/2010
Ron
>12/28/2009(ST.JOSEPH CATHOLIC CHURCH RESTROOM ADD'N'S
>CROSSROADS,NC
>Sullivan &
>Cozart
>12/29/2009
Dony
>
>There are a lot of spaces and characters. Like on the last entry. The
>user is "Don" and not "Dony".

The Delphi string type is stored in memory as one byte with the current
length of the string, followed by exactly that many characters.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
0
Tim
3/15/2010 2:01:46 AM
Sorru guys. I didn't have C#/project at home to test the code on over
the weekend. I'm back at work and have gone through all the help
you've given me.

Mike, I was able to get your code working. I had to change a little in
that it was throwing an error message about char's not being correct
for base64. A quick google search told me what I needed. Much
Thanks!  :D

Arne, I wasn't able to get your code to produce the same level of
results. That might be because I don't understand everything that's
going on with it. What happens is that it seems to repeat itself and
combine data together.
Here is the code I tried revising with no luck:

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        struct TRebarStruct
        {
            private byte RDlen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
            public string ReceiveDate;
            private byte JNlen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 150)]
            public string JobName;
            private byte COlen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
            public string Contractor;
            private byte ADlen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
            public string AssignDate;
            private byte DNlen;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
            public string DetailerName;
        }

        private void OpenFile_Click(object sender, EventArgs e)
        {
            Stream stm = new FileStream(@"C:\wtf.trk", FileMode.Open,
FileAccess.Read);
            TRebarStruct[] data = new TRebarStruct[10];
            int bufsiz = Marshal.SizeOf(typeof(TRebarStruct));
            byte[] b = new byte[bufsiz];
            IntPtr buf = Marshal.AllocHGlobal(bufsiz);
            for (int i = 0; i < data.Length; i++)
            {
                stm.Read(b, 0, b.Length);
                Marshal.Copy(b, 0, buf, b.Length);
                data[i] = (TRebarStruct)Marshal.PtrToStructure(buf,
                    typeof(TRebarStruct));
            }
            Marshal.FreeHGlobal(buf);
            stm.Close();
            for (int i = 0; i < data.Length; i++)
            {

                ListViewItem listitem = new
ListViewItem(data[i].ReceiveDate.ToString());
                //listitem.ImageIndex = 0;
                listitem.SubItems.Add(data[i].JobName.ToString());
                listitem.SubItems.Add(data[i].Contractor.ToString());
                listitem.SubItems.Add(data[i].AssignDate.ToString());
 
listitem.SubItems.Add(data[i].DetailerName.ToString());
                listView1.Items.Add(listitem);
            }
        }
0
Magus
3/15/2010 3:26:03 PM
> Sorru guys. I didn't have C#/project at home to test the code on over
> the weekend. I'm back at work and have gone through all the help
> you've given me.
> 
> Mike, I was able to get your code working. I had to change a little in
> that it was throwing an error message about char's not being correct
> for base64. A quick google search told me what I needed. Much
> Thanks!  :D

Sounds good.  I knew I was a genius!

-- 
Mike
GoTinker, C# Blog
http://www.gotinker.com 
0
Mike
3/15/2010 5:41:42 PM
On 15-03-2010 11:26, Magus wrote:
> Arne, I wasn't able to get your code to produce the same level of
> results. That might be because I don't understand everything that's
> going on with it. What happens is that it seems to repeat itself and
> combine data together.
> Here is the code I tried revising with no luck:
>
>          [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
>          struct TRebarStruct
>          {
>              private byte RDlen;
>              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
>              public string ReceiveDate;
>              private byte JNlen;
>              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 150)]
>              public string JobName;
>              private byte COlen;
>              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
>              public string Contractor;
>              private byte ADlen;
>              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
>              public string AssignDate;
>              private byte DNlen;
>              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
>              public string DetailerName;
>          }
>
>          private void OpenFile_Click(object sender, EventArgs e)
>          {
>              Stream stm = new FileStream(@"C:\wtf.trk", FileMode.Open,
> FileAccess.Read);
>              TRebarStruct[] data = new TRebarStruct[10];
>              int bufsiz = Marshal.SizeOf(typeof(TRebarStruct));
>              byte[] b = new byte[bufsiz];
>              IntPtr buf = Marshal.AllocHGlobal(bufsiz);
>              for (int i = 0; i<  data.Length; i++)
>              {
>                  stm.Read(b, 0, b.Length);
>                  Marshal.Copy(b, 0, buf, b.Length);
>                  data[i] = (TRebarStruct)Marshal.PtrToStructure(buf,
>                      typeof(TRebarStruct));
>              }
>              Marshal.FreeHGlobal(buf);
>              stm.Close();
>              for (int i = 0; i<  data.Length; i++)
>              {
>
>                  ListViewItem listitem = new
> ListViewItem(data[i].ReceiveDate.ToString());
>                  //listitem.ImageIndex = 0;
>                  listitem.SubItems.Add(data[i].JobName.ToString());
>                  listitem.SubItems.Add(data[i].Contractor.ToString());
>                  listitem.SubItems.Add(data[i].AssignDate.ToString());
>
> listitem.SubItems.Add(data[i].DetailerName.ToString());
>                  listView1.Items.Add(listitem);
>              }
>          }

I can not troubleshoot it based on "with no luck".

Arne
0
ISO
3/16/2010 12:29:08 AM
Reply:

Similar Artilces:

How to Convert UTC to localTIme(C# )
I have got the value of user account's lastlogon time. Its type is Int64. This value is stored as a large integer that represents the number of 100 nanosecond intervals since January 1, 1601 (UTC)(Refer to MSDN). I don't know how to convert this value to localTime. The following is my code. ################################################################ DirectoryEntry deUser = new DirectoryEntry(ldappath); DirectorySearcher src = new DirectorySearcher(deUser); src.Filter = "(&(objectClass=user)(SAMAccountName=" + accountNa...

how to convert date
Hi, I'm looking for some method to convert mail date, in format: eg. "Sun, 18 Sep 2005 20:57:08 +0200", to computer local time. I tried CTime but without resoults. m. Have you tried COleDateTime::ParseDateTime()? m.wski21.usunto@aust.com wrote: > Hi, > > I'm looking for some method to convert mail date, in format: > eg. "Sun, 18 Sep 2005 20:57:08 +0200", to computer local time. > I tried CTime but without resoults. > > m. >I'm looking for some method to convert mail date, in format: >eg. "Sun, 18 Sep 2005 20:57:08 +0200&qu...

Convert text to time value
I have a series of time values in a 'General' format. They are of the type: 184525 Which is 18:45:25 or 6:45:25 pm. A time which is am would be of the type: 12345 Which is 1:23:45 am. Is there a way to convert those 'General' values to an Excel serial so that I can figure out the difference between two times? I've seen a bunch of examples on the net, but none of those that I have found deal with this format that I can tell. Thanks. Hi try =--TEXT(A1,"00:00:00") -- Regards Frank Kabel Frankfurt, Germany "Andy" <amelton@gmail.com> schrieb...

How do I convert dates to text keeping the format?
I'm trying to convert a column of data in date format *m/d/yyyy to a text format without converting to serial numbers. Ie: I want to retain the mm/dd/yyyy format. Is there a way to do this? =TEXT(A1,"MM/DD"/YYYY") "sprlarry" <sprlarry@discussions.microsoft.com> wrote in message news:69669AA6-FD15-47D7-843D-FC768728BF7A@microsoft.com... > I'm trying to convert a column of data in date format *m/d/yyyy to a text > format without converting to serial numbers. Ie: I want to retain the > mm/dd/yyyy format. Is there a way to do this? That ...

Excel: Auto converting text to numbers
I am downloading an Excel sheet, and the numbers come in as text. It basically comes in as "33 %" but Excel registers this as text, not a percentage. I have a cell that will be used to add the numbers, but since they are text it doesn't work. Given this information, is there a way to convert the imported data into numbers. I would prefer to include this into my formula. The potential numbers are: 0, 1, 2, 3, 4, 0 %, 25 %, 33 %, 50 %, 67 %, 75 %, 100 %, and N/A I would prefer a function, again if possible, that could convert any number. Please note, the space between the nu...

Go To Record
I have a form where the user updates information in fields on a form that is set to Continuous Forms to mimic a data sheet. When it is necessary to add additional information, the user clicks a button that opens a seperate form for additional info that is not a part of every record. Example Two tables, tblone, tbltwo. Two forms, frmRequest (continuous forms mimicking a datasheet), frmDayApproval On frmRequest, Record 1 has data fields a, b, c, d filled in and are all stored on tblone. On frmRequest, Record 2 has data fileds a, b, c, d filled in and are also stored on tblone. However,...

how to convert excel's .cvf file to .csv file
...

Convert Access97 to 2000
Hello, we're currently running access97 and would like to convert it to 2000, but we don't know what is the administrator password for this database. Also this database is running on multi user and have difference permission for diffence users. Could someone help me how to do make this happen but keep the currently permission retaint. Thanks ...

Savings a/c cashflow doesn't show withdrawals
Money 2003 When I do a cashflow forecast for my savings a/c it doesn't take into account transfers to my "cash" account - the one I use to keep track of what I spend my cash on. Consequently when I do the cashflow it gives an unreal projection of savings. I wish I could save $3000 in 2 months but it's not going to happen... ...

related records in advanced find doesn't work
Hello, I have an advanced find where I am trying to bring in some information from the 'related to' lead on an appointment. No matter what lead field I select, no data is returned for that column. Has anyone seen this behavior or had any issues with this? Thanks! The 'related to' fields work as a seach filter criteria so you are specifying here which records to include in your search. The 'edit columns' option dictate the data columns visibly returned from the query. Regards Marion "jpop" wrote: > Hello, > > I have an advanced find w...

Convert 2000 Calendar to web page
Greetings, When I convert my calendar for 2005 to a webpage, the page is off by 1 day. Is there a template or fix available to fix this? Thanks, Duane I can edit the html file but this should not be the case. Fixes? Suggestions...other than use Apple? "Duane Perry" <dlp_sr@yahoo.com> wrote in message news:yZRtd.5561$0r.1710@newsread1.news.pas.earthlink.net... > Greetings, > > When I convert my calendar for 2005 to a webpage, the page is off by 1 day. > Is there a template or fix available to fix this? > > Thanks, > > Duane > > Duane, ...

XML Note convert to DataSet
Hello, I have this function: object acmResponse = acmLogin.acmString("4001", "", paramFormLogin + paramUserBasics);System.Xml.XmlNode[] acmNodes = (System.Xml.XmlNode[])acmResponse; What I have todo, to convert the XML Object in the DataSet Object? Thank you Matthias ...

Starting with no records for a filter
Hi, i have a subform that i filter based on some combo boxes at the top of the main form that the user can type into. i have a search method that is called using the following: call searchMethod(Nz(box1.value, ""), Nz(boz2.value,"") , ..... ) this search method then builds up an sql string to filter the records. this works well. when i initially load the form up, i have a minor problem. all of the records are shown, because all of the box values are "", and so there is effectively no filter. i actually want the opposite of this. i.e if the user doesnt se...

Convert
Is it possible to convert a Money file created in the USA version to that of the UK version? Thanks in advance The general way is QIF Export then Import. It's involved and has limitations like loan accounts don't QIF. See http://www.bollar.org/msmoney/#Q1. "Crispy" <nowayspammers@hotmail.com> wrote in message news:uQKSfzfyDHA.2500@TK2MSFTNGP09.phx.gbl... > Is it possible to convert a Money file created in the USA version to that of > the UK version? ...

Problem converting from Quicken to M2005
My Quicken files are mostly investment related, and generally converted fine. However all bonds (regular and muni's) converted as Investment type: Mutual Fund, not Bond. (1) How do I prevent that, (2) How do you change the Investment Type for an item? Thank you. In microsoft.public.money, Mike wrote: >My Quicken files are mostly investment related, and generally >converted fine. However all bonds (regular and muni's) converted as >Investment type: Mutual Fund, not Bond. (1) How do I prevent that, (2) Money typically converts custom data types from Quicken into funds. I thou...

Numbers converting to decimal
I a trying to figure out why when I type 11 and automatically converts it to .11, if I type 11. it will stay 11,if I change all the cells to text then back to number they willstay. I have checked the formatting of the cells, it even happens when I open a brand new worksheet. Any ideas? Thanks Dawn Hi Dawn, Tools>Option>Edit, uncheck Fixed Decimal -- Kind Regards, Niek Otten Microsoft MVP - Excel "DawnP" <anonymous@discussions.microsoft.com> wrote in message news:c3cf01c48a05$d75359d0$a501280a@phx.gbl... > I a trying to figure out why when I type 11 and &...

Converting Quicken 2004 to Money
Quicken 2004 has many bugs, and I have had it. The most recent being that it doesn't work AT ALL now that it is the year 2004. I have had to change the date on my computer today to open it. I want to get Money instead, however I do not know if Money can get my data from the 2004 version. Does anybody know for sure? Yes is the answer to the question you posed. No is the answer to the question you are getting to but didn't pose. M04 imports Q03 and earlier. If the past predicts the future M05 will import Q04. "Colin" <anonymous@discussions.microsoft.com> wrote ...

Count records added in current week
I'm trying to work out an expression that will return the number of records in a table that were added in the current week (Sun-Sat). I have a date field in the table. I have tried using a string I found on the forum (below), which was for quarters, tweaking for weeks, but am new to more complicated expressions and it returns an error. =DCount("*","tblRequests","[Date]>=" & Format(DateSerial(Year(Date()),3*(DatePart("ww",Date())-1)+1,1),"#mm\/dd\/yyyy#")) Any help most gratefully received. Tonia First day o...

Customizing "Convert Campaign Response"
We have created custom Fields in the Campaign Response entity that we would like to populate on the Lead Entity when we do a conversion. However it doesn't seem like this is possible from the Data Map. Is there a way to modify what fields are carried forward during a conversion, or do I need to find a different method? Thank you in advance. Hi, As I had some time left, I tried to figure this one out. To my surprise I can't find ANY direct link between a converted campaign response and a new lead. There is only an indirect link, through the campaign entity. But that does not ...

Converting from AOL to Outlook
Is there an efficient way for me to convert my AOL address book over to Outlook? Before I buy Outlook, I want to be sure I cam make the conversion without loosing the large address book I have on AOL. "Herb Clader" <Herb Clader@discussions.microsoft.com> wrote in message news:44A9739C-A94F-49AB-BF08-31D78A86CCB7@microsoft.com... > Is there an efficient way for me to convert my AOL address book over to > Outlook? > > Before I buy Outlook, I want to be sure I cam make the conversion without > loosing the large address book I have on AOL. AOL's help p...

Convert English language document to Hindi
Is there any software available to convert an English language text document to Hindi language document by using dictionary based translation (not transliteration). For example: The sentence : My name is Joseph Should be converted to : ???? ??? ????? ?? ...

Problem with AFX_THREAD_STATE class converting from VS6.0 to VS.NET 2003
I have inherited some code that works in VS6.0. It has code snippets like the following: _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); pThreadState->m_nLastHit = 0; and _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); CToolTipCtrl* pToolTip = pThreadState->m_pToolTip; It then does things with these values. In VS.NET, there is no member variable in _AFX_THREAD_STATE that corresponds to m_nLastHit or m_pToolTip. Have these been replaced by something similar in VS.NET 2003 that I can use? #if (_MFC_VER < 0x0700) _AFX_THREAD_STATE* pThreadState = AfxGetThrea...

Opening a form and subform to a specific record
I am using the time and billing database and I would like to be able to open an employee timesheet data form only for a specific person. I would like for an employee to only be able to view their time card and not others how can I do that. Use the WhereCondition argument of the OpenForm command. What Time and Billing db? LT AREA wrote: >I am using the time and billing database and I would like to be able to open >an employee timesheet data form only for a specific person. I would like for >an employee to only be able to view their time card and not others how can I >do t...

Converting Hours an minutes just into minutes #2
Is thier a formula to use to change hous and minutes, just into minutes ex: 01:30 (1 hour and 30 minutes) into 90 minutes. And how do you format the cells. Thank you Select the cell and change the format to: [m] -- Gary's Student "Six Sigma Blackbelt" wrote: > Is thier a formula to use to change hous and minutes, just into minutes ex: > 01:30 (1 hour and 30 minutes) into 90 minutes. And how do you format the > cells. > > Thank you ...

Save Record
In a modal pop up form's subform I wish to save a record without having to exit it so that a report reflects the current data in a control in the subform. Can anybody help please. -- Grimwadec "Grimwadec" <Grimwadec@discussions.microsoft.com> wrote in message news:35553A46-0359-44E1-9494-40A730112C26@microsoft.com... > In a modal pop up form's subform I wish to save a record without having to > exit it so that a report reflects the current data in a control in the > subform. Can anybody help please. > -- > Grimwadec In code behind th...