[fpc-pascal] how to initialize a SearchRec var?
Sven Barth
pascaldragon at googlemail.com
Fri Jan 3 10:46:19 CET 2014
Am 03.01.2014 10:34 schrieb "Graeme Geldenhuys" <graeme at geldenhuys.co.uk>:
>
> On 2014-01-02 19:21, waldo kitty wrote:
> >
> > we do not want to turn off hints so how can we initialize dirinfo and
make fpc
> > happy?
>
>
> I hate such hints too! This is what I did in my code to prevent that
> unwanted hint.
>
> One part is the usage of an out parameter, and the second part is the
> {$HINT OFF} directive.
>
>
> ----8<-------------8<-------------8<-------------8<-------------8<----
> program test_SearchRec;
>
> uses
> Dos;
>
> const
> pattern : string = '*.pas';
>
> var
> dirinfo : SearchRec;
>
> // prevents the compiler hint about not initialized variables
> procedure dcpFillChar(out x; count: SizeInt; Value: Byte);
> begin
> {$HINTS OFF}
> FillChar(x, count, value);
> {$HINTS ON}
> end;
>
>
> begin
>
> dcpFillchar(dirinfo,sizeof(dirinfo),$00);
> FindFirst(pattern,AnyFile,dirinfo);
> findclose(dirinfo);
> end.
> ----8<-------------8<-------------8<-------------8<-------------8<----
I would suggest to use the following sequence instead:
=== code begin ===
{$push}
{$hints off}
// whatever
{$pop}
=== code end ===
This way if the hints are switched off before that code is reached they
will stay off afterwards instead of being switched on.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140103/784046ef/attachment.html>
More information about the fpc-pascal
mailing list