Unit BtrDump;
interface
uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  Db,
  DbCtrls,

  bseDump;

Type
  TtbHexDump =
  Class( tHexDump )
    Private
      FDataLink  : TFieldDataLink;
      Procedure DataChange( Sender: TObject );
      function  GetDataSource: TDataSource;
      Procedure SetDataSource( Value: TDataSource );
      Procedure SetRecordSize;
    Protected
      Procedure Paint; override;
      Procedure Notification( AComponent: TComponent; Operation: TOperation ); Override;
    Public
      Constructor Create( AOwner: TComponent ); Override;
      Destructor Destroy; Override;
    Published
      Property DataSource: TDataSource read GetDataSource write SetDataSource;
  end;

implementation
Uses
  BseTable,
  BtrMain;

Constructor TtbHexDump.Create( AOwner: TComponent );
begin
  inherited Create( AOwner );
  FDataLink                := TFieldDataLink.Create;
  FDataLink.Control        := Self;
  FDataLink.OnDataChange   := DataChange;
  FDataLink.OnActiveChange := DataChange;
end;


Destructor TtbHexDump.Destroy;
begin
  FDataLink.OnDataChange   := NIL;
  FDataLink.OnActiveChange := NIL;
  FDataLink.Free;
  Inherited Destroy;
end;


Function TtbHexDump.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;


Procedure TtbHexDump.SetDataSource( Value: TDataSource );
begin
  FDataLink.DataSource := Value;
  If ( Value <> NIL ) and ( Value.Dataset <> NIL ) then
    SetRecordSize;
end;


Procedure TtbHexDump.SetRecordSize;
Var
  TrueTable : TBaseTable;
begin
  If ( FDataLink.DataSource.Dataset is TtbTable ) then
  begin
    TrueTable := TBaseTable( TtbTable( FDataLink.DataSource.Dataset ).Handle );
    If ( TrueTable <> NIL ) then
      DataSize  := TrueTable.BufferSize;
  end
  else
    DataSize := 0;
end;


Procedure TtbHexDump.DataChange( Sender: TObject );
begin
  If ( FDatalink <> NIL ) and ( FDataLink.DataSource.Dataset.Active ) then
  begin
    If ( DataSize = 0 ) then
      SetRecordSize;
    Address := FDataLink.DataSource.Dataset.ActiveBuffer;
  end;
end;


Procedure TtbHexDump.Notification( AComponent: TComponent;
  Operation: TOperation );
begin
  inherited Notification( AComponent, Operation );
  if ( Operation = opRemove ) and ( FDataLink <> NIL ) and
     ( AComponent = DataSource ) then
      DataSource := NIL;
end;


Procedure TtbHexDump.Paint;
begin
  Inherited Paint;
end;

end.
