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
1757 Views

Similar Articles

[PageSpeed] 30

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

appending unbound combo query data to new record
This may be covered elsewhere, but my understanding of how to phrase the question is limited at best. To set the scene - this is a dB for a weekly running club. I have a table "RunDetails" (holds details of runners in an event) which has a lookup field (the date) bound to table "Runs" (details of the event itself). Form PersData displays the details of runners (name, etc). On this form I have two unbound texboxes (Bib and Distance) and a date combobox (cbo.rowsource is query from table 'Runs') and a button to enter their ID, and the contents of t...

convert seconds to timecode format
Hi there, In C1 through to C800 i have values which represent seconds. (time) HOw can i convert that into 00:00:00:000 hours: mins: secs: fraction of secs so 3622.411 (secs) would equal 01:00:22:411 (3600 secs in an hour) thank you for any help or suggestions. John Try this. "G7"=3622.411 =INT(G7/3600) & ":" & INT(MOD(G7,3600)/60) & ":" &INT(MOD(G7,36))..... "JP" > Hi there, > > In C1 through to C800 i have values which represent seconds. (time) > > HOw can i convert that into > 00:00:00:000 &g...

How to convert two dates in to HH:MM:SS
Hi, I am trying to calculates the two dates cells diffrence int hour:minutes:seconds. could some help me in finding a solution i Excel sheet. eg. Cell A1 = Jan-01-2004 00:00 Cell B1 = Jan-02-2004 23:30 Cell C1 = 47:30 looking for a result like 47 hours 3 min. thanks sa -- sashaik ----------------------------------------------------------------------- sashaikh's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1555 View this thread: http://www.excelforum.com/showthread.php?threadid=27117 One way: C1: =B1-A1 Format C1 with Format/Cells/...

CRM 3.0 This record is read-only in Microsoft CRM error
CRM 3.0 running on a laptop with CRM laptop client(offline) installed. Every 20 minutes or so, a pop -up stating "This record is read-only in Microsoft CRM. Changes will not be synchronized to the MS CRM System". I cannot find anything online other than a KB article that this was fixed in version 3.0. Any ideas? Or better yet...any ideas how to determine which record is marked "read only"? anyone?? "Scott" <someone@nowhere.com> wrote in message news:d22a0$4b97d624$4ada8749$13991@FUSE.NET... > CRM 3.0 running on a laptop with CRM laptop client(...

relocating C:\inetpub to d:
my backend server currently have inetpub on c. I want to move it to d. Are there any problems with doing this for exchange 2000? here is a KB :) http://support.microsoft.com/default.aspx?scid=kb;en-us;261002 -- Jorge Patricio D�az Guzm�n MCP http://www.itpro.cl Este mensaje se proporciona "como est�" sin garant�as de ninguna clase, y no otorga ning�n derecho. This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. "tony" <none@none.com> escribi� en el mensaje news:OxH1RfBjFHA.3704@TK...

Second question converting seconds to hours
Thank you everyone for your help with my earlier issue. This might jus be a formatting problem, but I can't seem to figure this out. I' horrible working with time issues in excel. I have a raw number of 676953 in seconds and I need a formula t convert a number like this to 188:02:33. When I try formating wit hh:mm:ss it will only go to 24 hours and roll over. Does this make sense? Am I missing something? Thanks in advance. Chuc -- bagox ----------------------------------------------------------------------- bagoxc's Profile: http://www.excelforum.com/member.php?action...

Convert Lead > Account-Contact-Opportunity Error
Hi, I have several leads opened. If I create a new one it will work "but" especially with this ONE lead I don't get it, I convert it either to Account - Contacts or Opportunity and gives me the following error. I repeat this is only for this one. I tried to close reopen change settings etc... Still not working. Microsoft CRM Platform Error Report: Error Description: Exception from HRESULT: 0x80042F09. Error Details: Details on this error have not been provided by the platform. Error Number: 0x80042F09 Source File: Not available Line Number: Not available Date: 10-2...

Can I convert ComboBoxes to TextBoxes?
Is there a way to convert a ComboBox to a Text Box? I've got a group of Combo Boxes that are of the correct size and in the appropriate location on my worksheet. If there was a way to convert these to Text Boxes, which is what I need, it would be very helpful. Thanks in advance. Paul Hi Paul AFAIK you can't (you can in Access, but that doesn't help you very much!). -- Cheers JulieD check out www.hcts.net.au/tipsandtricks.htm ....well i'm working on it anyway "PCLIVE" <pclive@livenet.net> wrote in message news:ujjsGEqPFHA.164@TK2MSFTNGP12.phx.gbl... ...

Cannot link to record in Pub
I have MS small business office 2007 w/ Publisher, Outlook (w Bus. Contact Mgr "BCM"), etc. I use Outlook but haven't done anything with BCM. Everytime I open Publisher, I get the following message: "cannot link to record. Before you can link this item to a BCM record: -set outlook as your default email program; -create your outlook profile and complete the setup wizard for outlook 2007 w/ business contact mgr." I click the help button, and try to follow the sets but everything seems to be set. I really don't understand all this. Can anyone help?? -- ...

ccd+ addenda record for texas child support
Has anyone had anyluck building as eft ccd+ format for terxas child support without using 1 vendor per employee to use for paying we id'd 3 fields im can see and bring in for payables for the data but the data fields we see can't pull in t2 of the 3 when building the addenda record we are paying ~25 employee deductions at once required data is texas case # , ss#,non custodial parent name will cchange per each record we can impoort into pm dist ref,trans desc po# Mark, If You are a Microsoft Partner, You can also post your question in Dynamics GP partner forum to receive replies ...

Can record counter number on form disappear
I there a property or some way to make the record-counting number at the bottom of a form not show? Robert On Mon, 11 Jun 2007 23:00:48 -0400, "Robert" <cpq1bcle[REMOVE]@verizon.net> wrote: >I there a property or some way to make the record-counting number at the >bottom of a form not show? Set the "Navigation Buttons" property of the form to No. I believe they come in a packet - the five << < > >> *> buttons and the counter textbox. You can certainly program your own navigation buttons as a replacement if you want the arrow butto...

Query to join records according to "hierarchy"
My table is something like this: Fields: Name; Group John; 1-1 Carl; 1-1 Brian; 1-2 Charles; 2-1 Eddie; 2-2 Carmen; 3-1 Ellen; 3-2 ......and so on What I need is to combine the field Name in group 1-1 to 1-2, 2-2, 3-2. Then 2-1 with 2-2, 3-2. Then 3-1 with 3-2. Is this possible? If so, how can I do it? The results from the query would be something like this: Name A Name B Name C Name D John(1-1) Brian(1-2) Eddie(2-2) Ellen(3-2) Carl(...

XML Validation in C # 2.0
Hi, I am trying to validate an invalid-XML against an XSD. I am using an XmlReaderSettings to set the ValidationEventHandler, ValidationType and adding the Schema to the SchemaSet. The XML has quite a few validation errors in it. But the ValidationEventHandler is throwing only the first validation error. I have used XmlValidatingReader instead and it was listing all the validation errors. Since it has been made obsolete in Version 2.0 I would like to know how do i list all the validation errors of an XML in 2.0. Thanks moud wrote: > I am trying to validate an invalid-XML against an XSD. I...

xml transform using c#
i have a method which is return xml from a dataset. can someone please post some example code of how i can transform this xml using an xsl stylesheet? i am only interested in the c# part of the code, not the xsl. please note that my xml is coming from a method, not from a xml file. thanks. What is it returning from the method? A string, a stream, and XmlDocument, and XmlNode, an XmlReader? Supposing that the method returns a string: string xml = MyMethod(); System.IO.StringReader reader = newStringReader(xml); System.Xml.XPath.XPathDocument doc = new XPathDocument(reader); System.Xm...

How can i use usb port in visual c++?
I had resaearched this subject. I have learnt that i must find device driver which device i will use. My project is to write SMS sender program with gsm phone. I have Motorlola C336 gsm phone. That phone only USB port. I want to send sms through that phone and computer. How can use device driver to communicate with gsm phone from usb port. Do i have to have device driver manual? Please help me. I have read that I can use device driver function GetIOCtrl function but how do i learn that device driver has which function ? How can i solve thjis problem? Thank a lot ...

I need translation from C# to MFC
Hello guys! Can somebody translate this code for me: while (mWebBrowser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { Application.DoEvents(); } I specificaly need the line: Application.DoEvents(); Thanks in advance Mystique You'll need a message loop I guess. Something similar to :- while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } -- Regards, Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com "Mystique" <misic@softhome.net> wrote in message news:epDy5u7pFHA.1096@TK2M...

how to convert word file to excel file
i have one word file and needs to convert to excel. If it is in a TABLE - Copy the Table and paste into EXCEL. If not in a TABLE - select all of your document then on the MENU BAR - Select TABLE - CONVERT - TEXT TO TABLE - Copy the TABLE and paste into EXCEL. -- wjohnson ------------------------------------------------------------------------ wjohnson's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=29640 View this thread: http://www.excelforum.com/showthread.php?threadid=516088 ...

How do I convert US date with 12hr format to European date 24hr
I am using Excel. I have a mix of 24hr and 12hr AM/PM format pulling from a database. I want to reformat all dates with time to the 24hr clock so that I can then have 1 format to manipulate If the input data are formatted so that Excel recognises them as times, then it doesn't matter whether they are 12 hour or 24 hour format. If you want to change them all to one format, use Format/ Cells/ Number/ Time, and choose to suit your preference. You may have problems if your data are treated as text because they have spare spaces or non-breaking spaces. In that case you'd ha...

loop help with inserting records
I have a function that returns an integer - let's call that integer 'x'. How do I insert new records in a table equal to 'x' and insert something that's modified by x-1 on each pass through the loop? I'm trying to understand how this would function in Access and the loop function help doesn't explain it very well. In particular, I've got [startDate] and [endDate] - short date formatted. I have the difference between the two in months. Let's say 1/1/2000 and 3/1/2000. This would return '3' from my function and I would like 3 new records adde...

C# WinForms Objects
Hello all, I have a WinForms app that has a number of forms. When I login, I create 3 objects, lets call them A, B & C.When I create them, I connect to a database, return a load of data and set the members. I need to 'Save' these objects somewhere as I need to reference their members in number of the above mentioned forms, but I don't want to create them again, as it's another hit on the database. In ASP.NET, I'd keep them on a session, how would I do this in WinForms? Thanks, JY Jon wrote: > Hello all, > > I have a WinForms app that h...

Linked Table Cant Delete Record
I created a linked table in ms access 2003 to a sql server When I open up the linked table in datasheet view I cannot delete any records. Yet if I open up sql query analyzer I can delete all the records from the table, so I do not think it is a rights issue. I never had this problem. could it be something with the odbc connection to the sql server? Or any other ideas. Thanks James, Try RE-linking to the SQL Server... that would be remove the link and recreate it and see if you get the same behaviour. -- Gina Whipp 2010 Microsoft MVP (Access) "I feel I have been...

Standard C++ library compatibility with old declarations.
Hi - We are porting our code to use Roguewave ersion 6 off an older version. The newer version dictates that standard C++ library be adhered to. We also have some 3rd-party applications which have old header files in them like : #include <iostream.h> Compiling our apps in Visual Studio 6 but using standard c++ library throws errors at these "include" declarations prompting us to use new style as: #include <iostream> // I suppose We don't have access to 3rd-party code - so what is the workaround for this ? Is there a compiler directive/macro which I can use to al...

Printing reprot from a form for the record viewed
I would like to print a report (sort of an invoice) from a form where i am entering the final data for the invoice. but the report is generated for the entire table. for time being i am printing the form. but the actual report must have a different format and some more additional informations. So i want help to print the report only for the record viewed in the form and that i should be able to give the print commond from the form itself through the command button.thanks Try this link on "How To Print A Single Record from a Microsoft Access Form into a Report"http://www.databasedev.c...

converting tabular structures in a Word document into an actual table or reading data from the tabular structures using VBA code
I have a macro which can read the last cell/column of all tables in a Word 2003/2007 document and store the data in an MS-Access table. But, some Word documents have the data in structures like a table format but are not actually tables. The structure looks like a table, but the table borders are actually line connectors. These documents were created by a software(VeryPDF PDF to Word converter) which converted the PDF documents(the original format these documents were) into Word documents. 1. Is there a way I can convert/replace the tabular structures with actual tables in Word so t...

How to Handle Recording 401k Transactions
Please, someone help! Money's help features don't give me any clue to solving this issue. I'll keep this as brief as possible. 1. When I get a paycheck, I record it into Money using the Paycheck Deposit form - where you line-item Before and After Tax Deductions. There is a lump sum deduction for my 401k account, which I list under before tax deduction and record it as a transfer to 401k. 2. "401k" is the name for an investment account I've set up in Money. Therefore, this account shows a total of all my before tax contributions - but does not show indivi...