procedure CreateXMLBarcodeș
var
BinarySize: Integer;
InputString: utf8string;
StringAsBytes: array of Byte;
F : FIle of Byte;
pTemp : Pointer;
begin
InputString := '';
ADoc := TNativeXml.CreateName(rootName);
try
... //create the XML
InputString := ADoc.WriteToLocalString; //utf8string
if InputString > '' then begin
//serialize the XML string to array of bytes
BinarySize := (Length(InputString) + 1) * SizeOf(Char);
SetLength(StringAsBytes, BinarySize);
Move(InputString[1], StringAsBytes[0], BinarySize);
//save the array of bytes to file
AssignFile( F, xmlFilename );
Rewrite(F);
try
BinarySize := Length( StringAsBytes );
pTemp := @StringAsBytes[0];
BlockWrite(F, pTemp^, BinarySize );
finally
CloseFile( F );
end;
end;
finally
ADoc.Free;
end;
end
...
//in other procedure:
DataSet1XMLBarCode.LoadFromFile(CreateXMLBarcode);
...
//when I want to create the report
//create the DataMatrix image
procedure xyz(Sender: TfrxReportComponent);
var AWidth, AHeight: Integer;
function GetStringFromBlob: AnsiString;
var BlobStream: TStream;
begin
Result := '';
DataSet.Open;
BlobStream := DataSet1.
CreateBlobStream(DataSet1XMLBarCode, bmRead);
try
SetLength(Result, BlobStream.Size);
BlobStream.Position := 0;
BlobStream.Read(Result[1], BlobStream.Size);
finally
BlobStream.Free;
end;
DataSet.Close;
end;
begin
Barcode2D_DataMatrixEcc2001.Locked := True;
Barcode2D_DataMatrixEcc2001.Barcode := GetStringFromBlob;
Barcode2D_DataMatrixEcc2001.Module := 1;
Barcode2D_DataMatrixEcc2001.DrawToSize(AWidth, AHeight);
with TfrxPictureView(frxReport1.FindObject('Picture1')).Picture.Bitmap do
begin
Width := AWidth;
Height := AHeight;
Barcode2D_DataMatrixEcc2001.DrawTo(Canvas, 0, 0);
end;
Barcode2D_DataMatrixEcc2001.Locked := False;
end;
//the code was 'çopied'and adapted from the internet