Thanks for the update.
Looking forward to the class/template.
> Hello Everyone,
> Thanks to all who contributed suggestions. I have to say "thanks again"
to
> Arnor Baldvinsson for providing the answer to the problem <g>...
> As I had suspected, the main problem was in the prototype. The CRC32 was
> expecting a *STRING parameter, yet the dynamic string that I was
allocating
> was declared as &STRING. When I changed it to &CSTRING, it worked fine.
> I also moved the code to create the string inside the control CRC
function.
> The revised code is:
> ======================================
> MyClass.GetCRC Procedure(Long pFEQ)
> TheCString &CSTRING
> TheSize LONG
> CRCValue LONG
> Code
> !Get the size of the current control's contents
> TheSize = LEN(Contents(pFEQ))
> !Allocate a new string at the new max size
> TheCString &= NEW(CSTRING(TheSize + 1)) !Add 1 because the CRC
uses
> a STRING
> !Get the Data in this control
> TheCString = CONTENTS( pFEQ )
> !Get the CRC
> CRCValue = ControlMonitorCRC32( TheCString, SIZE(TheCString), 0 )
> !Dispose of the string
> DISPOSE(TheCString)
> !Return the new CRC value
> RETURN( CRCValue )
> ======================================
> This code returns a CRC for the contents of a control - no matter what the
> size.
> BTW - I plan to post the code for a class/template set (based on an idea
> that Arnor gave me for a solution to another post here on "The best place
to
> trigger a refresh") in a day or so. This is turning out to be a VERY
useful
> class and I'm quite happy to be able to pass it along for others to use!
> Charles Edmonds
> LANSRAD - "Intelligent Solutions for Universal Problems"
> www.lansrad.com
> > Hello Everyone,
> > I'm having some trouble getting a prototype worked out ( I *think* ).
> > Here is what I am up to:
> > 1) I want to generate a CRC on the contents of a field of unknown
> length.
> > 2) I want to write the class code so that it will *adjust* itself to
> the
> > maximum size field as needed.
> > For the CRC, I have this code from Randy Goodhew's book (THANKS Randy!):
> > ======================================
> > MAP
> > MODULE('CLARION 32 BIT API')
> > CRC32(*STRING buffer,ULONG size,ULONG crc),ULONG,RAW,NAME('CLA$CRC32')
> > END !module
> > END !map
> > where the parameters are:
> > buffer - the data buffer upon which to perform the CRC.
> > size - size (in bytes) of the data buffer.
> > crc - the initial CRC value, usually 0.
> > ======================================
> > The CRC code works fine, but it is prototyped to expect a pointer to a
> > string buffer. That is where I am running into problems.
> > ======================================
> > In my class code , I have these variables that are global to the class:
> > MaxDataString &STRING
> > MaxDataSize LONG
> > ======================================
> > When processing the Field (based on the FEQ number) I use this code to
> > determine if my string is large enough to hold the data returned by
> > CONTENTS() and I adjust the size if it is not:
> > MyClass.ValidateSize Procedure(Long pFEQ)
> > TheSize LONG
> > Code
> > !Get the size of the current control's contents
> > TheSize = LEN(Contents(pFEQ))
> > !If the size is greater than our allocated string space
> > IF TheSize > MaxDataSize
> > !If the string space allocated > 0
> > IF MaxDataSize > 0
> > !Dispose of the old string
> > DISPOSE(MaxDataString)
> > !Allocate a new string at the new max size
> > MaxDataString &= NEW(STRING(TheSize))
> > !Reset the max value
> > MaxDataSize = TheSize
> > ELSE
> > !Allocate a new string at the new max size
> > MaxDataString &= NEW(STRING(TheSize))
> > !Reset the max value
> > MaxDataSize = TheSize
> > END
> > END
> > ======================================
> > The code to validate the size will determine if the MaxStringData is
large
> > enough to hold the contents of the control that was passed and if it is
> not,
> > it will dispose of the string and create a NEW string of the right size.
> So
> > far so good.
> > ======================================
> > Next I want to get the CRC of the data in the control (now that I know
my
> > sting is big enough to hold it).
> > The code for this is below (note the call to the Self.ValidateSize(pFEQ)
> > MyClass.GetCRC Procedure(Long pFEQ)
> > CRCValue LONG
> > Code
> > !Validate that our MaxDataString is big enough - adjust if needed
> > Self.ValidateSize( pFEQ )
> > !Set the string to NULL
> > MaxDataString &= NULL
> > !Get the Data in this control and load it into the empty string
> > MaxDataString = CONTENTS( pFEQ )
> > !Get the CRC
> > CRCValue = CRC32( MaxDataString, SIZE(MaxDataString), 0 )
> > !Return the new CRC value
> > RETURN( CRCValue )
> > ======================================
> > Where I am running into problems is that the dynamic string
MaxDataString
> > which is declared as:
> > MaxDataString &STRING
> > does not match the prototype of the CRC32 function.
> > I may just be having a brain fart here, but I can't seem to figure out
how
> > to get the newly sized string into the CRC32 function.
> > Any help appreciated!
> > Thanks,
> > Charles Edmonds
> > LANSRAD - "Intelligent Solutions for Universal Problems"
> > www.lansrad.com