When setting a value such as -7.3 I get a rounding problem that would result in trying to set 07:17:60.0 resulting in a SAVESEC crash.
If the seconds are rounded up from 59.99999 to 60.0 then the seconds should be set to 0 and the other fields adjusted to compensate. This results in the following changes to CGCLatLongAbstractBase::SetDecimalDegrees
// Call utility function to break down decimal degrees value.
// Round up as needed.
// Since the GC_FLOAT_SECONDS_STYLE supports a seconds field
// that provides precision to 1/1000th of a second, I will
// multiply by 1000 and round up. Then use the floor() function
// to throw away garbage values.
Seconds = TruncDblSeconds(Seconds);
Seconds = 0;
Minutes = 0;
_SAVEDEG(Degrees); // Store degrees
_SAVEMIN(Minutes); // Store minutes
Ive used this control in the apst and it works fine however Ive just added it to a new program and I get a crash when I call SetDecimalDegrees(0.0); Through debug Ive found the crash occurs when the _SAVEDEG macro is called.
Any ideas as to what could be causing it - its driving me up the wall!
I would like to know how you are using these controls. Don't give out proprietary or classified information but let me know as best you can how you are using these controls. I would really like to know. They have proven very popular.
I corrected a small error that another reader (Tero) caught in the source code that is used to initialize the latitude/longitude control to some value. I also found that the last update was missing a needed preprocessor directive that would keep the context menu from functioning. The project settings have been updated for this. Also note that I have *some* code in place to support hard-coded strings for the context menu but not all code is there to support it. I didn't bother finishing it because I thought that the resource table was the best method. This does not interfer with the correct operation of the controls as implemented. However, if you feel the need to complete that implementation, feel free to do so. The resource table method makes it easier to make changes to support other languages.
I have received a lot of great feedback on this code as well as the code accompanying my article on "Multi-Field Edit Controls -- A Whole New Class of Edit Controls" and a related control class, my "UTM Coordinate Control".
Thanks for the feedback. I hope to have time soon to contribute more articles to this site.
Thanks. I did not catch that. The function is used when initializing a value and I was concentrating on getting other code to work that I overlooked this. It is clearly and editorial error since I set the variable "result" to one thing in the line before and then set to something else in the line in question. I will submit and update soon.
There's a bug in CGCLatLongAbstractBase::TruncDblSeconds function.
double CGCLatLongAbstractBase::TruncDblSeconds(const double Seconds)
// This must be kept consistent with the parameters passed to the
// CGCDoubleField constructor for the floating-point seconds field
// support object (see private method DefineFields()).
double result = 0.0;
int factor = 1 * int(pow(10.0,double(FLTSECPRECISION)));
result = Seconds * factor + 0.5;
result = floor(Seconds);
result /= factor;
The problem lies in result = floor(Seconds); line. If seconds were f.ex. 59.0 you would get 0.059 as a result. Correct line would be result = floor(result);. Works for me anyway.