please , suppose i have this Binary Tree structure :
Type
TPMyTree = ^TMyTree;
TMyTree = Record
ID:Integer;
FullName:String[50];//<-------- fixed
addrs:String[50] // <----------- fixed
LeftT:TPMyTree;
RightT:TPMyTree;
end;
How could i save and load it from a Stream ?
When working with streams, the most complex issue is dealing with variable-length data. In your case that’s the
FullNameand theaddrs, because those fields are of typeString. The easiest solution is to use Delphi’s stream reader and writer helper classes,TReaderandTWriter, because they provide easy means of working with string. Other thant that the most obvious solution is to write the tree to the stream recursively, one node at a time.Warning, code written in browser window: