TRVAControlPanel.OnCustomFileOperation

<< Click to display table of contents >>

TRVAControlPanel.OnCustomFileOperation

Occurs when the application needs to save or load a file in a custom format.

type

  TRVAFileOperation = (rvafoOpen, rvafoSave, rvafoExport, rvafoInsert);

  TRVCustomFileOperationEvent = procedure (Sender: TrvAction

    Edit: TCustomRichViewEdit; const FileName: TRVUnicodeString;

    Operation: TRVAFileOperation; var SaveFormat: TrvFileSaveFilter;

    var CustomFilterIndex: Integer; var Success: Boolean) of object;

 

property OnCustomFileOperation: TRVCustomFileOperationEvent;

This event occurs when the following actions are executed:

TrvActionOpen (Operation=rvafoOpen)

TrvActionSave (Operation=rvafoSave)

TrvActionExport (Operation=rvafoExport)

TrvActionInsertFile (Operation=rvafoInsertFile)

FileName is a file name (full path) for opening/saving.

CustomFilterIndex is an index of custom format (in the CustomFilter property of the corresponding action), from 1.

For an opening operation, you can define a saving format in SaveFormat parameter (this format will be used for subsequent saving of document loaded from this file); you can also change CustomFilterIndex (on input, it corresponds to TrvActionOpen.CustomFilter; on output, it must correspond to TrvActionSaveAs.CustomFilter, if SaveFormat=ffeCustom). For all other operations, SaveFormat and output value of CustomFilterIndex are ignored.

Set Success to True if you loaded/saved file successfully.

See also:

TrvActionSave.SuppressNextErrorMessage

You can use LoadCSV function to implement an insertion of CSV files.

Example

Let you implemented saving and loading TRichView in your format. Let its extension is 'myf'.

Let you implemented the functions:

function SaveToMyFormat(Edit: TCustomRichViewEdit; 
  const FileName: TRVUnicodeString): Boolean;
function LoadFromMyFormat(Edit: TCustomRichViewEdit;
  const FileName: TRVUnicodeString): Boolean;

These function must return True on success.

First, assign CustomFilter property of TrvActionOpen and TrvActionSaveAs. You can do it at design time in the Object Inspector, or in code:

  rvActionsResource.rvActionOpen1.CustomFilter :=
    'My Files (*.myf)|*.myf';
  rvActionsResource.rvActionSaveAs1.CustomFilter :=
    'My Files (*.myf)|*.myf';

Make sure that ffiCustom is in TrvActionOpen.Filter, and ffeCustom is in TrvActionSaveAs.Filter.

Next, process RVAContolPanel.OnCustomFileOperation event:

procedure TForm3.RVAControlPanel1CustomFileOperation(Sender: TrvAction;

  Edit: TCustomRichViewEdit; const FileName: TRVUnicodeString;

  Operation: TRVAFileOperation; var SaveFormat: TrvFileSaveFilter;

  var CustomFilterIndex: Integer; var Success: Boolean);

begin

  case Operation of

    rvafoOpen:

      begin

        try

          // This example assumes that there is only one custom open 

          // format, so it does not check CustomFilterIndex 

          // (it must be 1)

          Success := LoadFromMyFormat(Edit, FileName);

      end;

    rvafoSave:

      begin

          // This example assumes that there is only one custom save

          // format, so it does not check CustomFilterIndex

          // (it must be 1)      

          Success := SaveToMyFormat(Edit, FileName);

      end;

  end;

end;