Modify the filename of the Save dialog?

General TRichView support forum. Please post your questions here
Post Reply
starhu
Posts: 49
Joined: Fri Jan 17, 2014 6:33 pm

Modify the filename of the Save dialog?

Post by starhu »

Hello,

I use the following code to create a new document (using another file as base):
srvActionsResource.rvActionNew1.Execute;
MainForm.ActiveEditor.RichViewEdit.LoadRVF(ExtractFilePath(ParamStr(0))+'MyFiles\'+DocName);


MainForm.ActiveEditor.Format;

MainForm.SRVTabSet1.Tabs[MainForm.SRVTabSet1.TabIndex].Text := 'My business card 1';

My problem is that when I click on Save, in the Save dialog the filename is which was set in the RvaControlPanel.DefaultFileName.

Can I set the filename each time to what I need? e.g. 'My business card 1', 'My business card 2' etc.

Thank you
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you want to assign a file name to the editor, load it using rvActionOpen1.LoadFile:

Code: Select all

srvActionsResource.rvActionOpen1.LoadFile(MainForm.ActiveEditor.RichViewEdit,
 ExtractFilePath(ParamStr(0))+'MyFiles\'+DocName, ffiRVF);
starhu
Posts: 49
Joined: Fri Jan 17, 2014 6:33 pm

Post by starhu »

Hello,

It is slightly more complicated.

The customer wants the following:

1.choose a base document from the list (I populate a sub menu with the available base documents for him)

2.The program opens a New document
srvActionsResource.rvActionNew1.Execute;
MainForm.ActiveEditor.RichViewEdit.LoadRVF(ExtractFilePath(ParamStr(0))+'MyFiles\'+DocName);

It is very important for the customer that the new documents should have a name (therefore I use MainForm.SRVTabSet1.Tabs[MainForm.SRVTabSet1.TabIndex].Text := 'My business card '+sNumber; ) but they should be in memory and not in a saved file

3.At Save the program should set the filename in the Save dialog to the same as the MainForm.SRVTabSet1.Tabs[MainForm.SRVTabSet1.TabIndex].Text

Your method

Code: Select all

srvActionsResource.rvActionOpen1.LoadFile(MainForm.ActiveEditor.RichViewEdit,
 ExtractFilePath(ParamStr(0))+'MyFiles\'+DocName, ffiRVF);
is not good for him because the *real* base document will be loaded which should not be modified any time.

Thank you
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Try

Code: Select all

srvActionsResource.rvActionNew1.Execute; 
MainForm.ActiveEditor.RichViewEdit.LoadRVF(ExtractFilePath(ParamStr(0))+'MyFiles\'+DocName); 
srvActionsResource.rvActionSave1.GetDoc(MainForm.ActiveEditor.RichViewEdit).FileName := DocName;
starhu
Posts: 49
Joined: Fri Jan 17, 2014 6:33 pm

Post by starhu »

Hello,

At runtime

Code: Select all

srvActionsResource.rvActionSave1.GetDoc(MainForm.ActiveEditor.RichViewEdit).FileName := DocName;
gives me access violation... :(

Thank you
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think it because GetDoc returns nil for MainForm.ActiveEditor.RichViewEdit.

It means no document information is associated by RichViewActions with this editor.

Is srvActionsResource.rvActionNew1.Execute called for the editor which is later available as MainForm.ActiveEditor? Probably not, otherwise it should work.

As a test, I added in the ActionTestTabs demo, in the procedure TForm3.OnNewEditor, after the line

Code: Select all

  srvActionsResource.rvActionNew1.ExecuteTarget(ActiveEditor.RichViewEdit);
the following code:

Code: Select all

  srvActionsResource.rvActionSave1.GetDoc(ActiveEditor.RichViewEdit).FileName := 'it works.rvf';
It works - when I call Save, the default file name is 'it works.rvf'.
(however, a new tab is still called 'Untitled.rvf', because its name is assigned TForm3.rvActionSave1DocumentFileChange, and this event is called in rvActionNew1.ExecuteTarget)
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Actually, there is a simpler solution - you can assign the desired file name to RVAControlPanel.DefaultFileName before executing rvActionNew.
But it is required that this action is executed for the editor.
starhu
Posts: 49
Joined: Fri Jan 17, 2014 6:33 pm

Post by starhu »

Hello,

The code you gave:

Code: Select all

srvActionsResource.rvActionSave1.GetDoc(ActiveEditor.RichViewEdit).FileName := 'it works.rvf';
Works very well for all the tabs, except the first.

Perhaps because the first tab / editor already exists.

And If I use it like this:

MainForm.ActiveEditor.RichViewEdit.LoadRVF(ExtractFilePath(ParamStr(0))+DocName);
MainForm.ActiveEditor.Format;

srvActionsResource.rvActionSave1.GetDoc(MainForm.ActiveEditor.RichViewEdit).FileName := 'it works1.rvf';
then I get get Access violation.

Thank you
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

GetDoc returns the proper object for the given editor only if this editor is already known to RichViewActions, i.e. a New or an Open action was executed for this editor.
Otherwise it returns nil and you get AV when accessing properties of an object returned by this function.
starhu
Posts: 49
Joined: Fri Jan 17, 2014 6:33 pm

Post by starhu »

Thank you. This info helped me solve the problem.
Post Reply