(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)

unit AHMTDBMemoView;
interface
{$I AHM.INC}
uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, DBCtrls, ExtCtrls, Buttons,AHMDialogClass,DB
  {$IFNDEF AHMINPRISE3},DBTables{$ENDIF};

type
  TAHMDBMemoView = class(TAHMAdvDialogComponent)
  private
    freadonly : Boolean;
    FFieldDataLink: TFieldDataLink;
    function GetDataField : String;
    procedure SetDataField(Value: String );
    function GetDataSource : TDataSource;
    procedure SetDataSource( Value : TDataSource );
  protected
    procedure Notification(AComponent: TComponent;Operation: TOperation); override;
  public
    constructor Create( AOwner: TComponent ); override;
    destructor Destroy; override;
    function Execute: Boolean; override;
  published
    property Readonly : Boolean read freadonly write freadonly default false;
    property DataField: String read GetDataField write SetDataField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;
  end;


implementation


type
  TAHMMemoViewForm = class(TForm)
  private
    DBMemo1: TDBMemo;
  public
    procedure Setupform;
  end;

procedure TAHMMemoViewForm.SetupForm;
begin
  DBMemo1 :=TDBMemo.Create(Self);
  with DBMemo1 do
  begin
    Parent:=Self;
    Align := alClient;
  end;
end;


function TAHMDBMemoView.Execute: Boolean;
var MemoViewForm: TAHMMemoViewForm;
begin
  if (ffielddatalink<>nil) and (Datasource<>nil) then
  begin
    MemoViewForm:= TAHMMemoViewForm.CreateNew(Application);
    with MemoViewForm do
    try
      SetFormProperties(MemoViewForm);
      SetupForm;
      DBMemo1.Readonly:=freadonly;
      DBMemo1.DataSource := DataSource;
      DBMemo1.DataField := DataField;
      ShowModal;
      if FFieldDataLink.Edit then DataSource.DataSet.Post
                             else DataSource.DataSet.Cancel;
    finally
      Free;
    end;
    result := true;
  end else result:=false;
end;

procedure TAHMDBMemoView.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FFieldDataLink <> nil) and (AComponent = DataSource) then SetDataSource(nil);
end;

function TAHMDBMemoView.GetDataField: String;
begin
  Result := FFieldDataLink.FieldName;
end;

procedure TAHMDBMemoView.SetDataField(Value : String);
begin
  FFieldDataLink.FieldName := Value;
end;

function TAHMDBMemoView.GetDataSource: TDataSource;
begin
  GetDataSource := FFieldDataLink.DataSource;
end;

procedure TAHMDBMemoView.SetDataSource(Value : TDataSource);
begin
  FFieldDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;

destructor TAHMDBMemoView.Destroy;
begin
  FFieldDataLink.Free;
  inherited Destroy;
end;

constructor TAHMDBMemoView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FReadonly := false;
  FFieldDataLink := TFieldDataLink.Create;
end;

end.
