[fpc-pascal] Problem with array of const
tony.whyman at mccallumwhyman.com
Sun Oct 29 16:26:08 CET 2017
I've fallen into various traps with array of const before. I would
always recommend that:
1. Test the vType before accessing the argument value and raise an
exception if it is not what is expected. You are dealing with a free
union and the compiler may not always do what you expect it to.
2. Values such as VAnsiString are best dealt with as PChars as otherwise
you can quickly get into problems with reference counts.
procedure test(name: string; args: array of const);
case args.vType of
raise Exception.Create('Unexpected vtype');
Use of "strpas" is probably unnecessary in the above, but it does
illustrate the point.
On 28/10/17 23:59, Darius Blaszyk wrote:
> Consider the application below. When I run it I do get the following
> In other words I lose the first character (a) from the arguments
> supplied and the string returns with a lot of garbage. What am I doing
> wrong here?
> Rgds, Darius
> program test_args;
> procedure test(name: string; args: array of const);
> test('name', ['arg']);
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal