[fpc-pascal] Initializing Arrays?

Jürgen Hestermann juergen.hestermann at gmx.de
Thu Dec 25 10:10:50 CET 2008


I've already read that its not built into pascal but how do I get around 
this?

If you use AnsiStrings they should be always initialized (as far as I 
know). But most other (and all selfdefined) types are not.

If you want to initialize a whole array in one step you can use:

    fillchar(contacts,sizeof(contacts),#0);

which fills the whole array with zeros.
For the first element it could be

    fillchar(contacts[1],sizeof(contacts[1]),#0);

But if you have an array with lots of shortstrings it may be more 
efficient to do it as you wrote, because then only one byte per 
shortstring (the length byte) is written.

> Also if I am passing a var to a procedure how would use a pointer as 
> parameter?

To declare a var parameter you need to do this:

    procedure JSMContactAdd(var contact : JSMContact);

Defining a var parameter tells the compiler to use the pointer to the
variable instead of coping it to a temporary (local) variable.


Jürgen Hestermann.





More information about the fpc-pascal mailing list