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" <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 |
![]() |
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 |
![]() |
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 |
![]() |
> 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 |
![]() |
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 |
![]() |
> 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 |
![]() |
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= SIENPLixLWS4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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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 |
![]() |
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 |
![]() |
"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 |
![]() |
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 |
![]() |
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 |
![]() |
> 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 |
![]() |
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 |
![]() |