[Lazarus] PDF generator, try 2

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Apr 7 12:27:49 CEST 2016


On 2016-03-31 16:48, silvioprog wrote:
> +{$IFDEF VER3}
> +      Buffer := Default(TBuffer)
> +{$ELSE}
> +      FillChar(Buffer,SizeOf(TBuffer),0)
> +{$ENDIF};


Just thought I would mention, I've seen the above code listed a few
times now to remove the famous "Local variable does not seem to be
initialized" compiler hint.

Well, it might work on FPC 3.0 (not test), but it does nothing for FPC
2.6.4 - the hint is always there. I know it is a harmless hint, if the
code was correct to start work.

Either way, I found a solution for that, which I used in fpGUI's DocView
help viewer application too.

Implement the following:

procedure FillMem(Dest: pointer; Size: longint; Data: Byte );
begin
  FillChar(Dest^, Size, Data);
end;

Then write your code as follows:

  FillMem(@Buffer, SizeOf(TBuffer), 0);


Now the compiler hint is gone under both FPC 2.6.4 and FPC 3.0 - and no
ugly IFDEF's required.  And as a bonus the name FillMem() is more
descriptive and technically accurate of what the code does than FillChar()


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp




More information about the Lazarus mailing list