[simpits-tech] OT: Delphi Record problems

Erwin Neyt simpits-tech@simpits.org
Sun, 22 Dec 2002 12:32:27 +0100


Actualy you can stream a complete instance of this class to a file, but you
have to use 'two-step' approach to load it back in, due to the unkown  size
of the 'numbers'.

A better way is to store the 'normal' class member vars in a structured file
(for example XML) and store the data ('numbers') in a separate data file.

I once tried to stream a complex class (recursive class with unknown size)
in one run, but ended up writing streaming for every class member. It's
tiresome but often there is no 'easy' way to do this.

Erwin.



> -----Original Message-----
> From: Stig Joergensen [mailto:stig.joergensen@clearsky.dk] 
> Sent: zaterdag 21 december 2002 21:12
> To: simpits-tech@simpits.org
> Subject: RE: [simpits-tech] OT: Delphi Record problems
> 
> 
> Thanks Erwin
> 
> I was thinking of this also - but that produces a new 
> problem.... can not load the file directly, but only one item 
> at a time....
> 
> /Stig
> 
> 
> -----Original Message-----
> From: Erwin Neyt [mailto:rwntn@hvv.nl]
> Sent: 21. december 2002 20:27
> To: simpits-tech@simpits.org
> Subject: RE: [simpits-tech] OT: Delphi Record problems
> 
> 
> Stig,
> 
> You right about numbers being just a pointer.
> 
> And because of this the SizeOf any TMYRec instance will be 
> always the same.
> 
> I suggest you make TMyRec into a class and write a function 
> to increase/decrease the 'numbers' size.
> 
> TMyClass = class
>   type : integer;
>   size : integer;
>   name : array[0..7] of char
>   count : integer;
>   numbers : array of integer
>   state : integer;  
>   procedure SetSize(NewSize: integer);
> end;
> 
> implementation
> 
> procedure TMyClass.SetSize(NewSize: integer)
> Begin
>   // alloc new memory for numbers 
>   SetLength(numbers, NewSize);
>   size := NewSize;
> End;
> 
> Now you can query MyClass.size to get the current size if the 
> numbers instance.
> 
> Hope this helps
> 
> Erwin.
> 
> 
> > -----Original Message-----
> > From: Stig Joergensen [mailto:stig.joergensen@clearsky.dk]
> > Sent: zaterdag 21 december 2002 16:52
> > To: simpits-tech@simpits.org
> > Subject: [simpits-tech] OT: Delphi Record problems
> > 
> > 
> > Sorry for the OT, but i have a problem i Delphi, and some of
> > you might know the answer
> > 
> > 
> > 
> > 
> > I have a problem with record that i for the life of me can
> > not get a handle on:
> > 
> > say i have a file that are organized like this
> > 
> > 
> > 0000000100000001abcdefgh00000003111111112222222233333333000000
> > 00........
> > .
> > 
> > 
> > 
> > i have create a record that match the above
> > 
> > TMYRec = packed record
> >   type : integer;
> >   size : integer;
> >   name : array[0..7] of char
> >   count : integer;
> >   numbers : array of integer
> >   state : integer;
> > ...
> > ...
> > ...
> > end;
> > 
> > myrec : TMyRec;
> > 
> > so i set the size of "numbers" to the "count", one would 
> hope that the
> > sizeof(MyRec) would reflect the change, but this is not the
> > case, which leaves me to beleave that the "numbers" is just a 
> > pointer....
> > 
> > any idea how i can expand the "numbers" at runtime to reflect
> > the content of the file?
> > 
> > /Stig
> > 
> > 
> > 
> > ------------------------ Yahoo! Groups Sponsor
> > ---------------------~--> Get 128 Bit SSL Encryption! 
> > http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA> /i7folB/TM
> > 
> > 
> > --------------------------------------------------------------
> > -------~->
> > 
> > The Delphi Collection Web Site!
> > http://www.delphicollection.com/public/index.s> html
> > 
> > ---------------------------------------------------------------
> > Unsubscribe:delphi-programming-unsubscribe@yahoogroups.com
> > List owner:delphi-programming-owner@yahoogroups.com
> > ---------------------------------------------------------------
> > 
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/ 
> > 
> > 
> > 
> > _______________________________________________
> > Simpits-tech mailing list
> > Simpits-tech@simpits.org
> > http://www.simpits.org/mailman/listinfo/simpit> s-tech
> > To 
> > unsubscribe, please see the instructions at the 
> > bottom of the above page.  Thanks!
> > 
> 
> _______________________________________________
> Simpits-tech mailing list
> Simpits-tech@simpits.org
> http://www.simpits.org/mailman/listinfo/simpits-tech
> To unsubscribe, please see the instructions at the bottom of the above
> page.  Thanks!
> _______________________________________________
> Simpits-tech mailing list
> Simpits-tech@simpits.org
> http://www.simpits.org/mailman/listinfo/simpits-tech
> To unsubscribe, please see the instructions at the bottom of 
> the above page.  Thanks!
>