{*************************************************************************}
{ Rave Reports version 7.0                                                }
{ Copyright (c), 1995-2006, Nevrona Designs, all rights reserved          }
{*************************************************************************}

unit QRpDBUtil;

interface

uses
  Types, QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls,
  SysUtils, Classes, DB, QRpDefine, QRpMemo;

type
  TDBMemoBuf = class(TMemoBuf)
  protected
    procedure SetMemoField(Value: TMemoField);
    procedure SetRTFMemoField(Value: TMemoField);
  public
    property Field: TMemoField write SetMemoField;
    property RTFField: TMemoField write SetRTFMemoField;
  end; { TDBMemoBuf }

  procedure GraphicFieldToBitmap(GraphicField: TBlobField; Bitmap: TBitmap);

implementation

  procedure TDBMemoBuf.SetMemoField(Value: TMemoField);
  var
    Stream: TMemoryStream;
  begin { SetMemoField }
    Stream := TMemoryStream.Create; { Create temporary stream }
    try
      if not Value.IsBLOB then begin
        Stream.SetSize(Value.DataSize);
        Value.GetData(Stream.Memory);
      end else begin
        (Value as TBlobField).SaveToStream(Stream);
      end; { else }
      SetData(Stream.Memory^,Stream.Size); { Set memo buffer data to stream }
    finally
      Stream.Free; { Free up temporary stream }
    end; { try }
  end;  { SetMemoField }

  procedure TDBMemoBuf.SetRTFMemoField(Value: TMemoField);
  begin { SetRTFMemoField }
    ReadRTF := true;
    SetMemoField(Value);
  end;  { SetRTFMemoField }

  procedure GraphicFieldToBitmap(GraphicField: TBlobField; Bitmap: TBitmap);
  begin { GraphicFieldToBitmap }
    Bitmap.Assign(GraphicField);
  end;  { GraphicFieldToBitmap }

end.