[DUG] Sizeof record gives error

2011-08-24 Thread David Moorhouse (DUG)
I have the following code snippet code type PConstArray = ^TConstArray; TConstArray = array of TVarRec; function CreateConstArray(const Elements: array of const): TConstArray; type TLogType = (ltError, ltWarn, ltInfo); PLogData = ^TLogData; TLogData = record LogType: TLogType;

Re: [DUG] Sizeof record gives error

2011-08-24 Thread Colin Johnsun
Haven't got into the details of your problem, but here is an article which goes into the details of array of const. http://rvelthuis.de/articles/articles-openarr.html Hope it helps, Cheers, Colin On 25 August 2011 09:40, David Moorhouse (DUG) del...@moorhouse.net.nz wrote: I have the

Re: [DUG] Sizeof record gives error

2011-08-24 Thread Robo
I think your TLogData contains storage for an integer (TLogType, 4 bytes), and a pointer to an array (4 bytes). However, what you need is enough memory to store the entire array, not just the pointer, so you should get the size of the array to get the correct size. On Thu, Aug 25, 2011 at 11:40

Re: [DUG] Sizeof record gives error

2011-08-24 Thread David Moorhouse (DUG)
Thanks Colin The TVarRec and open array stuff come from Rudy's page - very helpful too :) D Haven't got into the details of your problem, but here is an article which goes into the details of array of const. http://rvelthuis.de/articles/articles-openarr.html Hope it helps, Cheers,

Re: [DUG] Sizeof record gives error

2011-08-24 Thread David Moorhouse (DUG)
Thanks Robo In my mind the memory layout looks like this (attempt at ascii art follows) TLogData - LogType = 4 bytes - LogArgs - TConstArray - length = 4 bytes - data pointer = 4 bytes Regardless of the Length of the array, if I allocate 16 bytes the code works

Re: [DUG] Sizeof record gives error

2011-08-24 Thread kaller
sure ok. On Thu, 25 Aug 2011 11:57:26 +1200, Robo wrote: I think your TLogData contains storage for an integer (TLogType, 4 bytes), and a pointer to an array (4 bytes). However, what you need is enough memory to store the entire array, not just the pointer, so you should get the size of

Re: [DUG] Sizeof record gives error

2011-08-24 Thread Jeremy Coulter
Just hard code 16 in David and we can discuss it we we do a code review :-) On Thu, Aug 25, 2011 at 12:36 PM, kal...@ihug.co.nz wrote: sure ok. On Thu, 25 Aug 2011 11:57:26 +1200, Robo robo...@gmail.com wrote: I think your TLogData contains storage for an integer (TLogType, 4 bytes),

Re: [DUG] [computing] Sizeof record gives error

2011-08-24 Thread Peter Ingham
Another attempt to reply... First thing to do is determine if the crash occurs in the procedure call, on the subsequent assign, or in between. Give this a try: procedure TUserClass.Log(const LogType: TLogType; const Args: array of const ); var LogData: PLogData; TempArgs :