unit VCardFile;

interface

uses
  Classes, SysUtils, VCard, DataFile;

type
  { TVCardFile }

  TVCardFile = class(TDataFile)
  private
    procedure VCardModify(Sender: TObject);
  public
    VCard: TVCard;
    function GetFileName: string; override;
    function GetFileExt: string; override;
    function GetFileFilter: string; override;
    procedure SaveToFile(FileName: string); override;
    procedure LoadFromFile(FileName: string); override;
    procedure Assign(Source: TPersistent); override;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;


implementation

resourcestring
  SVCardFile = 'vCard file';

{ TVCardFile }

procedure TVCardFile.VCardModify(Sender: TObject);
begin
  Modified := True;
end;

function TVCardFile.GetFileName: string;
begin
  Result := SVCardFile;
end;

function TVCardFile.GetFileExt: string;
begin
  Result := VCardFileExt;
end;

function TVCardFile.GetFileFilter: string;
begin
  Result := GetFileName + ' (' + GetFileExt + ')|*' + GetFileExt + '|' + inherited;
end;

procedure TVCardFile.SaveToFile(FileName: string);
begin
  inherited;
  VCard.SaveToFile(FileName);
end;

procedure TVCardFile.LoadFromFile(FileName: string);
begin
  inherited;
  VCard.LoadFromFile(FileName);
end;

procedure TVCardFile.Assign(Source: TPersistent);
begin
  inherited;
  VCard.Assign(TVCardFile(Source).VCard)
end;

constructor TVCardFile.Create(AOwner: TComponent);
begin
  inherited;
  VCard := TVCard.Create(nil);
  VCard.OnModify := VCardModify;
end;

destructor TVCardFile.Destroy;
begin
  FreeAndNil(VCard);
  inherited;
end;

end.

