Ver Mensaje Individual
  #2  
Antiguo 30-04-2019
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.275
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Bueno la idea es sencilla.
SimpleGraph te da opciones de recorrer los objetos y acceder a todas sus propiedades y también te da opciones por código para crear nuevos elementos.

La idea es que al guardar, puedas recorrer los objetos que existen en el grafo y sus propiedades y almacenarlas en una tabla (posición, colores,...). En mi caso almacenaba sólo algunas porque los objetos eran siempre del mismo tiupo y con algunas variaciones.

Para recuperar
, debes realizar el caso contrario. Recorrer la tabla e ir creando objetos dinámicamente según las propiedades almacenadas.

Te adjunto un código sencillo que funciona para que cojas la idea de cómo hacerlo.


Código Delphi [-]

procedure TMainForm.btnGrabarClick(Sender: TObject);
var
  i, oc:Integer;
  o:TGraphObject;
  FIni:TIniFile;
begin

  // Crear un  INI
  FIni := TIniFile.CReate(ChangeFileExt(Application.ExeName, '.ini'));
  try
    oc := SimpleGraph.ObjectsCount;
    // Recorrer los objetos creados en el grafo
    for I := 0 to (SimpleGraph.Objects.Count - 1) do begin
      o := SimpleGraph.Objects.Items[i];
      // Es un nodo
      if (o is TGraphNode) then begin
        // Acceder à la clase
        FIni.WriteString('OBJ'+IntToStr(i), 'Clase', TGraphNode(o).ClassName);
        // posicion del objeto
        FIni.WriteString('OBJ'+IntToStr(i), 'Left', IntToStr(TGraphNode(o).Left));
        FIni.WriteString('OBJ'+IntToStr(i), 'Top', IntToStr(TGraphNode(o).Top));
        FIni.WriteString('OBJ'+IntToStr(i), 'Ancho', IntToStr(TGraphNode(o).Width));
        FIni.WriteString('OBJ'+IntToStr(i), 'Alto', IntToStr(TGraphNode(o).Height));
        // Color de fondo
        FIni.WriteString('OBJ'+IntToStr(i), 'Color', IntToStr(TGraphNode(o).Brush.Color));
        // ...

      end;
    end;
  finally
    FreeAndNil(FIni);
  end;
end;

procedure TMainForm.btnRecuperarClick(Sender: TObject);
var
  i, oc:Integer;
  o:TGraphObject;
  FIni:TIniFile;
  secc:TStringList;
  str:String;
  Rect:TRect;

  // Obtener la clase del Nodo
  function GetNodeClass(AClass:string):TGraphNodeClass;
  begin
    if (AClass = 'TRectangularNode') then
      Result := TRectangularNode;
  end;

begin

  // Commando por defecto
  SimpleGraph.CommandMode := cmInsertNode;
  // Fichero de objetos
  FIni := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
  secc := TStringList.CReate;
  try
    // Leer la lista de nodos a crear
    FIni.ReadSections(secc);
    // Recorerr los nodos a crear
    for i := 0 to (secc.Count - 1) do begin
      // Clase del nodo
      Str := FIni.ReadString('OBJ' + IntToStr(i), 'Clase', 'TRectangularNode');
      // Definir la clase
      SimpleGraph.DefaultNodeClass := GetNodeClass(Str);
      // Posicion del objeto
      Rect.Left := FIni.ReadInteger('OBJ' + IntToStr(i), 'Left', 10);
      Rect.Top := FIni.ReadInteger('OBJ' + IntToStr(i), 'Top', 10);
      Rect.Width := FIni.ReadInteger('OBJ' + IntToStr(i), 'Ancho', 100);
      Rect.Height := FIni.ReadInteger('OBJ' + IntToStr(i), 'Alto', 50);
      // Crear el nodo
      o := SimpleGraph.InsertNode(Rect);
      // color de fondo..
      TGraphNode(o).Brush.Color := FIni.ReadInteger('OBJ' + IntToStr(i), 'Color', 0);
      // Otras propiedades...
    end;
  finally
    FreeAndNil(FIni);
    FreeAndNil(secc);
  end;
end;
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita