Hi
I am using Delphi XE8 with TMS Diagram Studio V4.24.01
Using the built in editor TDiagramEditor (editor) I can save and load a file using the file open and save buttons on the editor.
When programmatically saving a file using editor.Diagram.SavetoFile() which essentially executes the same code as the editor buttons. I get an exception '$C0000005 ACCESS VIOLATION'.
Please provide more details, specially because you said the built-in code works, and your custom code doesn't not. We cannot guess what's going on at your side. Code you are using, offending line, call stack, etc.
The following was sent via email. Looks like the forum messed it up a bit lol.
In the supplied Demos\Simple\DiagramDemo a made the following changes
unit fMain;
…
In TForrm1 class..
private
procedure EditorCreate(Sender: TObject);
+ procedure EditorSave(Sender: TObject);
In TForm1.FormCreate..
DiagramEditor1.OnCreateDesigner := EditorCreate;
+ DiagramEditor1.OnSaveDiagram := EditorSave;
DiagramEditor1.Execute;
+ // ADDED THIS PROCEDURE TO FORCE SAVING TO SINGLE FILE
+ //
+ procedure TForm1.EditorSave(Sender: TObject);
+ begin
+
+ TfmDiagramEditor(Sender).Diagram.SaveToFile('tempfille.dgr');
+
+ // ALSO TRIED BELOW
+ // diagramEditor1.Diagram.SaveToFile('tempfile.dgr');
+
When I the save the file I get the exception.
This break’s here
procedure TatDiagram.SaveToFile(const AFileName: string);
var
MemStream: TMemoryStream;
FileStream: TFileStream;
begin
MemStream := TMemoryStream.Create;
try
FileStream := TFileStream.Create(AFileName, fmCreate);
try
>> SaveToStream(MemStream);
MemStream.Seek(0, soFromBeginning);
ObjectBinaryToText(MemStream, FileStream);
finally
FileStream.Free;
end;
finally
MemStream.Free
end;
end;
Please let me know if you need more information.
Thanks
AndyC
From OnEditorCreate event you can save a reference to the TatDiagram object, and then reuse it in the OnSaveDiagram event. The diagram reference is never modified until you close the editor.