Delphi multi-TList data file
Posted by eeleong on April 12, 2001 at 14:08:44:
I have create an data-structure using TList, but have problem save it into file. .... Data Structure is something like this, A:TList; B:TList C:TList D:TResullt TResult=class(TPersistent) begin Property FValue; Property FResult; end; ....... I add several different TResult object into C , and several different C into B and several B into A. Everything work quite well But I have problem with saving All information in A into a file. I have tried the following way: 1. Save as Typed file- failed as Object cannot save as typed file (violated polymorishim rule), Then I tried to change the TResult into a Record instead of Class, but the same problem still arrive when I want to save B. 2.Save as UnTyped binary File –In order to create untyped file , the information have to read from a buffer, but i dont know how to send A to a buffer. I try to treat A as buffer but failed. ( regarding the binary file , how should i know how much memory to allocate to it , if the
file will be getting larger and larger.) 3. Use TStream, having problem with send A into buffer. 4. Use TFiler/TWriter/TReader ...... I manage to do save it when i have a list of TResult,i.e. several TResult object into C , and save the C but I dont know how to extend it further. TFiler only do standard data type( int,string ,componet) file IO, but i really dont know how to ask them to write or read TList. I saw a abstract method know as Write/Read ,but I really dont know how to make it to suitable my data-type. I think there is a way to use TFiler and recursive algorithm to do the File IO, but i am not too sure how to do it , I hope it is not too complicated. I welcome any suggestion , even on DataStructure. finally I am using Delphi 2.
Related Articles and Replies:
DelphiLand FAQ
DelphiLand -- Delphi Tutorials
|