[fpc-pascal]Two questions on initialisation of variables

Peter Vreman peter at freepascal.org
Thu Mar 21 07:21:30 CET 2002


> > In Delphi mode you can use
> > 
> > VAR v : type = value;
> > 
> > for global variables as well.
> hmmm... I suppose I can use Delphi mode for Go32, can't I?

Delphi mode is independent of the target OS. It are language features

> I have recompiled it with -Sd, and I get lots of new bugs, all of them 
> being of the form:
> Error: incompatible type for arg nº 1: Got <unkonwn type>, expected
THI> S 
> or THAT...
> I'll have to check that... (I am using a quite old version of the 
> compiler yet, so this may be an old bug!)

Try using -S2 that will turn on the delphi features but keep the fpc style of checking for
things like procedure variables

> Will Delphi mode create DJGPP-linkable code, even if I don't use classes 
> and exceptions?

See first answer

> >>And the second is for initialisation of PChars. The examples of
> >>reference guide, pag 29, seem to suggest that I don't need to New()
> >>pchars. Is that right? I suppose this is only at initialisaton time.
> >>
> > 
> > This only works when you assign a constant string to the pchar.
> > 
> > 
> >>Suppose that for some reason I had to new a PChar, I suppose that New()
> >>would only allocate 1 byte, so I'd have to use GetMem, am I right??
> >>GetMem (p, maxsize+1);
> >>
> > 
> > You should use the methods from the strings unit as mentioned in the
> > docs... otoh stralloc() for example just calls getmem()...
> > I recommend using ansistrings instead of pchars.
> 
> I have read about AnsiStrings, and it seems reasonable to me. I am using 
> PChars just for two reasons: to be able to link with DJGPP and to be 
> able to trigger direct DOS system calls that require pointers to 
> null-terminated strings, and AnsiStrings, seem to fit well...
> 
> I suppose I can't use the + operator to concatenate AnsiStrings, can I?

You can use all the normal string operations you have also for shortstrings (normal pascal
strings)







More information about the fpc-pascal mailing list