xsharp.eu • Size of Char[] array?
Page 1 of 1

Size of Char[] array?

Posted: Wed Mar 01, 2023 7:26 pm
by stefan.ungemach
This code gives me a warning XS9021 in the red line:

...
pResult := Char[]{dwResult}
XSharp.ADS.ACE.AdsGetString(self:_hADT, cFieldName, pResult, @dwResult, ADS_NONE)
...

PUBLIC STATIC METHOD AdsGetString(hTable As PTR, lFieldOrdinal As DWORD, pucBuf As CHAR[], pulLen Ref DWORD, usOption As WORD) As DWORD

Problem is that the called method wants a DWORD as 4. parameter, and it can indeed fill a buffer which is larger than MAX_WORD. How can I prepare a large buffer other than the red line's code?

Size of Char[] array?

Posted: Wed Mar 01, 2023 8:10 pm
by Chris
Hi Stefan,

The constructor of the System.Array class expects an integer (elements of the array), that's why you get the warning. I guess it's very unlikely that the dwResult var will ever hold a number greater than MAX LONG INT :), so you can just convert it to INT: pResult := Char[]{ INT(dwResult) }

Size of Char[] array?

Posted: Wed Mar 01, 2023 8:16 pm
by stefan.ungemach
Hi Chris, thanks, that did the trick.

BTW: Apologies for so many stupid questions, but I've finally started to migrate our complex VO framework to XSharp - and that's 1.5 millions of code lines ;)

Size of Char[] array?

Posted: Wed Mar 01, 2023 10:05 pm
by Chris
Hi Stefan,

Please don't worry at all, there are no stupid questions :)
Good luck with your migration, please don't hesitate to ask anything!

Size of Char[] array?

Posted: Thu Mar 02, 2023 9:45 am
by robert
Stefan
At first, it may look strange that some of these functions accept a signed number. How can you ever create an array with a negative number of elements?
The reason for this is that although the .Net system supports unsigned number, these were initially not part of what is called the Common Language Specification (CLS), so .Net languages did not have to support them to be "first class" .Net languages.

https://essentialcsharp.com/common-lang ... cification

Therefore, the constructors for many types only take signed integers.
And methods like IndexOf() and properties like Length also return signed integers. They often use -1 as special value to indicate that for example IndexOf() did not find anything.
The VO developers used 1 based indexes for characters in a string and elements in an array. They use 0 as special value and used unsigned integers for sizes and indices.

Robert