[fpc-pascal] how to initialize a SearchRec var?
Graeme Geldenhuys
graeme at geldenhuys.co.uk
Fri Jan 3 01:50:30 CET 2014
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<----
And here is the compiler output:
[tmp]$ fpc -viwnh test_SearchRec.pas
Hint: Start of reading config file /home/graemeg/.fpc.cfg
Hint: End of reading config file /home/graemeg/.fpc.cfg
Free Pascal Compiler version 2.6.2 [2013/02/10] for x86_64
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: FreeBSD for x86-64
Compiling test_SearchRec.pas
Linking test_SearchRec
25 lines compiled, 0.0 sec
2 hint(s) issued
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
More information about the fpc-pascal
mailing list