Prev: Center a HtmlElement in WebBrowser
Next: PictureBox on a Panel -- display scrollbars for large pics?
From: Magus on 12 Mar 2010 12:37 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?
From: Mike Lovell on 12 Mar 2010 12:45 "Magus" <mr.magus(a)gmail.com> wrote in message news:c234d4d2-221a-4389-802c-a1eaada8791c(a)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
From: Willem van Rumpt on 12 Mar 2010 13:17 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
From: Magus on 12 Mar 2010 13:24 On Mar 12, 1:17 pm, Willem van Rumpt <noth...(a)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#....
From: Mike Lovell on 12 Mar 2010 14:10 > 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
|
Next
|
Last
Pages: 1 2 3 Prev: Center a HtmlElement in WebBrowser Next: PictureBox on a Panel -- display scrollbars for large pics? |