Hello,
Thanks a lot for your suggestions.
However, by reading your answer I see no easy way to solve my problem.
In fact, there are to main patterns for using FillChar() in the code I work on: 1- Strings initialization as in the sample code bellow. For these cases, the first workaround you suggest works well and it is no big deal to change the code. 2- Records initialization. This is most of the FillChar() calls. The records (around 600 of them) are used to map on rows of tables in an Informix database. They contain various data types and strings as well. These strings are SUN Pascal Varying[n] Of Char. Internally, there are 4 bytes indicating the current string length and an Array of n Char. Since FillChar() is called with Chr(0) on them, this actually sets the current string length to 0 and fill them with zeroes. In this case, I think the best approach will be to generate procedures to do the records initialization field by field and call them instead of FillChar(). With a moderate amount of work, my translation program should be able to take care of this.
Also, when trying some ways to solve my problem, I encountered a behaviour that I don't clearly understand regarding the "Capacity" field: If I FillChar() a String with Chr(0), the Capacity field is set to 0 - as expected - that's my problem :-(. Then, if I pass this string as Var parameter to a procedure, I cannot put anything in it. There is no runtime error or warning, but the string stays empty, WriteLn() does not show anything - in the procedure or after returning from it -. But, If I re-initialize the string directly (S10 := 'AAAAA' for example): 1- the Capacity field stays 0 - that's normal 2- but I can now use WriteLn() on it and it shows what I put in it ('AAAAA').
What is exactly the role of the "Capacity" field? Is this an expected behaviour? Did I missed something?
Thanks again for your help. It is always fast and efficient.
Regards
Pascal Viandier pascal@accovia.com
Pascal Viandier wrote:
Do you think it is possible to modify the prcedure "FillChar()" to make it work correctly with the type String(xx)?
For example the code: VAR S10 : String(10); .... FillChar(S10, 10, 'A');
That's not how it's meant to work ("defined" by UCSD/BP). Do:
SetLength (S10, 10); FilLChar (S10[1], 10, 'A');
Note the `[1]'.
This has chances to work with various string formats.
Or look at StringOfChar (GPC unit).
Snip
Also, if this cannot be done or desirable from your point of view, is
there
a way to override the build-in FillChar() for one of mine
FillChar is not a reserved word, just a predefined identifier. You can override it as other identifiers.
that would be called for the type String(xx) only?
Just give it a `var s: String' parameter. The built-in version will then not be available anymore, of course.
Of course, you can rename your new routine. I don't know how easy or difficult it would be -- you only mentioned the total size of 600000 lines, but that's irrelevant as most of those lines do not contain FillChar, I suppose. You could do it semi-automatically, by first renaming all occurrences to the new name, and then renaming back those that do not compile with your routine (and therefore are not strings).
Does the case with arrays/records containing strings actually occur in the program?
Which kind of strings does Sun Pascal use? Strings with a length field (and if so, does its FillChar do what you want on an array/record containing such strings)? Or simply (packed) arrays of Char, as by ISO 7185. In this case, you can do the same in GPC and FillChar will work on them.
Frank