Page 1 of 1

Simplegraph - how to work with the field "Data"?

PostPosted: October 6th, 2010, 2:45 am
by slavapro
Hello All!

The objects Node and Link is have the field DATA (TPointer). I would like to store additional parameters (Trecord or TObject) in these objects.

1. Will save the settings when you save SimpleGraph?

2. Please give sample code to work with these field.

Thanks in advance,
slavapro

Re: Simplegraph - how to work with the field "Data"?

PostPosted: October 6th, 2010, 3:05 am
by Kambiz
Use OnObjectWrite event to save additional data of objects to the output stream, and use OnObjectRead event to load the additional data from the input stream.

Re: Simplegraph - how to work with the field "Data"?

PostPosted: October 6th, 2010, 11:58 am
by slavapro
Thanks for the quick response!

However, the description of the process is very scant. Could you give an example code?

Re: Simplegraph - how to work with the field "Data"?

PostPosted: October 6th, 2010, 12:23 pm
by Kambiz
It's very simple.

Code: Select all
type
  PExtraObjectData = ^TExtraObjectData;
  TExtraObjectData = record
    CreationDate: TDateTime;
    ModifiedDate: TDateTime;
  end;

procedure TForm1.SimpleGraph1ObjectWrite(Graph: TSimpleGraph;
  GraphObject: TGraphObject; Stream: TStream);
begin
  if Assigned(GraphObject.Data) then
    Stream.Write(GraphObject.Data^, SizeOf(TExtraObjectData));
end;

procedure TForm1.SimpleGraph1ObjectRead(Graph: TSimpleGraph;
  GraphObject: TGraphObject; Stream: TStream);
begin
  if not Assigned(GraphObject.Data) then
    GraphObject.Data := AllocMem(SizeOf(TExtraObjectData));
  Stream.Read(GraphObject.Data^, SizeOf(TExtraObjectData));
end;

Re: Simplegraph - how to work with the field "Data"?

PostPosted: October 6th, 2010, 12:59 pm
by slavapro
Thank you!
Really very simple.