How to convert Delphi Record to C#?

M

Magus

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?
 
M

Mike Lovell

Magus said:
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.
 
W

Willem van Rumpt

Magus said:
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.
 
M

Magus

Magus said:
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.

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 do begin
Jobs.ReceiveDate := Caption;
Jobs.JobName := SubItems[0];
Jobs.Contractor := SubItems[1];
Jobs.AssignDate := SubItems[2];
Jobs.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);
end;
finally
System.CloseFile(MyJobFile);
end;
end;

I did find another article that is almost what I'm needing:
http://groups.google.com/group/micr...+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#....
 
M

Mike Lovell

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 do begin
Jobs.ReceiveDate := Caption;
Jobs.JobName := SubItems[0];
Jobs.Contractor := SubItems[1];
Jobs.AssignDate := SubItems[2];
Jobs.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);
end;
finally
System.CloseFile(MyJobFile);
end;
end;

I did find another article that is almost what I'm needing:
http://groups.google.com/group/micr...+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.
 
M

Magus

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 do begin
       Jobs.ReceiveDate := Caption;
       Jobs.JobName := SubItems[0];
       Jobs.Contractor := SubItems[1];
       Jobs.AssignDate := SubItems[2];
       Jobs.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);
   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.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?  It's a two minute codingjob
to write something to do this for you.


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".
 
M

Mike Lovell

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
 
M

Magus

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

Ok, here is the output:

CjAzLzEyLzIwMTADQkpLQyBDYXZlaW5nbyAxLDAwMCwwMDAgR0FMLERPTUUgRS02OTQ4IEFEQUlSIENPLixLWS4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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VNDLi1TRUxMRVJTQlVSR0dBTCxET01FIEUtNjk0OCBBREFJUiBDTy4sS1kuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABdIdWVsc21hbi1Td2VlbmV5IENvbnN0LgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACjAxLzA4LzIwMTADRG9uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACjAxLzA1LzIwMTA1Q0FMRFdFTEwgVEFOSyAxLDAwMCwwMDAgR0FMLERPTUUgRS02OTQ4IEFEQUlSIENPLixLWS4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADkNhbGR3ZWxsIFRhbmtzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKMDEvMDYvMjAxMANEb24AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 
M

Mike Lovell

Ok, here is the output:

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


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
}
 
A

Arne Vajhøj

Magus said:
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.

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 do begin
Jobs.ReceiveDate := Caption;
Jobs.JobName := SubItems[0];
Jobs.Contractor := SubItems[1];
Jobs.AssignDate := SubItems[2];
Jobs.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);
end;
finally
System.CloseFile(MyJobFile);
end;
end;

I did find another article that is almost what I'm needing:
http://groups.google.com/group/micr...+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);
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 = (TFooBar)Marshal.PtrToStructure(buf,
typeof(TFooBar));
}
Marshal.FreeHGlobal(buf);
stm.Close();
for(int i = 0; i < data.Length; i++)
{
Console.WriteLine(data.a + " " + data.b + " " +
data.c);
}
Console.ReadKey();
}
}
}

Arne
 
M

Mike Lovell

Magus said:
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,
 
T

Tim Roberts

Magus said:
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.
 
M

Magus

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 = (TRebarStruct)Marshal.PtrToStructure(buf,
typeof(TRebarStruct));
}
Marshal.FreeHGlobal(buf);
stm.Close();
for (int i = 0; i < data.Length; i++)
{

ListViewItem listitem = new
ListViewItem(data.ReceiveDate.ToString());
//listitem.ImageIndex = 0;
listitem.SubItems.Add(data.JobName.ToString());
listitem.SubItems.Add(data.Contractor.ToString());
listitem.SubItems.Add(data.AssignDate.ToString());

listitem.SubItems.Add(data.DetailerName.ToString());
listView1.Items.Add(listitem);
}
}
 
M

Mike Lovell

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!
 
A

Arne Vajhøj

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 = (TRebarStruct)Marshal.PtrToStructure(buf,
typeof(TRebarStruct));
}
Marshal.FreeHGlobal(buf);
stm.Close();
for (int i = 0; i< data.Length; i++)
{

ListViewItem listitem = new
ListViewItem(data.ReceiveDate.ToString());
//listitem.ImageIndex = 0;
listitem.SubItems.Add(data.JobName.ToString());
listitem.SubItems.Add(data.Contractor.ToString());
listitem.SubItems.Add(data.AssignDate.ToString());

listitem.SubItems.Add(data.DetailerName.ToString());
listView1.Items.Add(listitem);
}
}


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

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top