Modification of the variable used to accommodate the element into the glass changes the element itself



  • The programme is written in IDE lazarus 1.6. There's a class with this announcement:

    DataForm = class
        public
            Choices:longint;
            BackUp:boolean;
        private
            nameForm:String;
            operationForm:TypeOperation;
        public
            function getForm():String;
            procedure setForm(const nForm:String);
            function getOperation():TypeOperation;
            procedure setOperation(const oForm:TypeOperation);
    end;
    

    And such a description:

    function DataForm.getForm():String;
    begin
         getForm:=nameForm;
    end;
    procedure DataForm.setForm(const nForm : String);
    begin
         nameForm:=nForm;
    end;
    

    function DataForm.getOperation():TypeOperation;
    begin
    getOperation:=operationForm;
    end;

    procedure DataForm.setOperation(const oForm:TypeOperation);
    begin
    operationForm:=oForm;
    end;

    For the operation of glass from the class of such objects, uses gstack;

    type     iStack = specialize TStack<DataForm>;
    var TopForm: iStack;
    CurrentStatus:DataForm;

    The button application form shall be such as:

       TopForm.CleanupInstance;
    CurrentStatus.setForm('fRoot');
    CurrentStatus.setOperation(oRoot);
    TopForm.Push(CurrentStatus);

    CurrentStatus.setForm('fViewPatientStory');
    CurrentStatus.setOperation(View);
    TopForm.Push(CurrentStatus);

    CurrentStatus.setForm('fViewPatient');
    CurrentStatus.setOperation(View);
    ShowMessage(TopForm.Top().getForm());

    TopForm.Pop;
    ShowMessage(TopForm.Top().getForm());

    2 messages are issued: fViewPatient.
    I need the elements placed in the glass to remain with the same values as they were at the time of the room, and so any element of the glazing refers to the currentStatus variable and, when it changes, all the grid elements change. Please help.



  • CurrentStatus := DataForm.Create;
    CurrentStatus.setForm('fRoot');
    CurrentStatus.setOperation(oRoot);
    TopForm.Push(CurrentStatus);
    
    CurrentStatus := DataForm.Create;
    CurrentStatus.setForm('fViewPatientStory');
    CurrentStatus.setOperation(View);
    TopForm.Push(CurrentStatus);
    
    CurrentStatus := DataForm.Create;
    CurrentStatus.setForm('fViewPatient');
    CurrentStatus.setOperation(View);
    ShowMessage(TopForm.Top().getForm());
    
    TopForm.Pop;
    ShowMessage(TopForm.Top().getForm()); 
    

    And don't forget to release the memory of the three CurrentStatus if TStack doesn't do it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2