Page 1 of 1
Modify the filename of the Save dialog?
Posted: Wed Feb 19, 2014 2:02 pm
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
Posted: Wed Feb 19, 2014 3:19 pm
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);
Posted: Wed Feb 19, 2014 3:51 pm
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
Posted: Wed Feb 19, 2014 4:29 pm
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;
Posted: Wed Feb 19, 2014 5:49 pm
by starhu
Hello,
At runtime
Code: Select all
srvActionsResource.rvActionSave1.GetDoc(MainForm.ActiveEditor.RichViewEdit).FileName := DocName;
gives me access violation...
Thank you
Posted: Wed Feb 19, 2014 6:06 pm
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)
Posted: Wed Feb 19, 2014 6:07 pm
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.
Posted: Fri Feb 21, 2014 7:19 pm
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
Posted: Fri Feb 21, 2014 8:07 pm
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.
Posted: Sun Feb 23, 2014 11:02 am
by starhu
Thank you. This info helped me solve the problem.