0 units in uses section, maybe just SysUtils allowed
Joking?
OK, let me take up the challenge...
The first thing which comes to my mind is LazBarcodes, available via Online-Package-Manager in Lazarus. It can generate QRCodes in pure Pascal code:
https://wiki.lazarus.freepascal.org/LazBarcodes. Although based on the zint library it does not require any external libraries. It is built around Lazarus LCL though, and thus far away from "0 units in uses section".
But there is also a more puristic qrcode generator in the fpc sources: packages/fcl-image; a sample project is in packages/fcl-image/examples. Here is another sample project:
program project1;
uses
fpqrcodegen, fpimgqrcode, fpWritePng;
const
TEXT_STRING = 'This is a qrcode generated by fpc.';
FILE_NAME = 'qrcode.png';
var
qrcode: TImageQRCodeGenerator;
begin
qrcode := TImageQRCodeGenerator.Create;
try
qrcode.PixelSize := 4;
qrcode.Border := 8;
qrcode.ErrorCorrectionLevel := EccHigh;
qrcode.Generate(TEXT_STRING);
qrcode.SaveToFile(FILE_NAME);
finally
qrcode.Free;
end;
end.
Or, even more puristic, just 0 and 1, the same code, but skipping the generation of the image. Like this:
program project2;
uses
fpqrcodegen;
const
TEXT_STRING = 'This is a qrcode generated by fpc.';
var
qrcode: TQRCodeGenerator;
x,y: Integer;
begin
qrcode := TQRCodeGenerator.Create;
try
qrcode.ErrorCorrectionLevel := EccHigh;
qrcode.Generate(TEXT_STRING);
for y := 0 to qrcode.Size-1 do
begin
for x := 0 to qrcode.Size-1 do
if qrcode.Bits[x,y] then
Write('x')
else
Write(' ');
WriteLn;
end;
finally
qrcode.Free;
end;
ReadLn;
end.
The used unit fpqrcodegen depends only on SysUtils.
cant use classes, nothing in uses section except for SysUtils.
Looking at fpqrcodegen in more detail I see that the class TQCodeGenerator is just a container to have everything at its own place. You could remove the class from the unit and use the other public functions to do the work. This leads to
program project3;
uses
simpleqrcodegen;
const
TEXT_STRING = 'This is a qrcode generated by fpc.';
var
x,y: Integer;
qrbuffer: TQRBuffer = nil;
tmpbuffer: TQRBuffer = nil;
size: Integer;
begin
SetLength(qrBuffer, QRBUFFER_LEN_MAX);
SetLength(tmpBuffer, QRBUFFER_LEN_MAX);
if QREncodeText(TEXT_STRING, tmpBuffer, qrBuffer, EccHIGH, QRVERSIONMIN, QRVERSIONMAX, mp0, false) then
begin
size := QRGetSize(qrBuffer);
WriteLn('success');
WriteLn('Size: ', size);
for y := 0 to size-1 do
begin
for x := 0 to size-1 do
if QRGetModule(qrBuffer, x, y) then
Write('x')
else
Write(' ');
WriteLn;
end;
end;
ReadLn;
end.
Unit "simpleqrcodegen" is the stripped-down version of fpqrcodegen which you can find in the attachment.