cancel
Showing results for 
Search instead for 
Did you mean: 

Clean, Close or Remove Form

former_member192187
Participant
0 Kudos

Hej All

I have a problem with close, clean or remove Form. I declared oForm=SBOApplication.... etc

In first run form all is right but in second one appear error: Form already Open. How is good way?

regards

Krzysztof Sala

Accepted Solutions (1)

Accepted Solutions (1)

former_member192187
Participant
0 Kudos

I not use LoadForm, I use build Form in my application.

Krzysztof Sala

rasmuswulff_jensen
Active Contributor
0 Kudos

If you want mulitlbe instances of the same window you'll need to autogenerate a unique form-uid.. Like this:


public static string GenerateUniqueFormUID(string WantedFormUID) {
  bool uidFound = false;
  int identifier=0;
  while(!uidFound) {
    if(!IsFormOpen(WantedFormUID+identifier,false)) {
      WantedFormUID+=identifier;
      uidFound=true;
    }
    else {
      identifier++;
    }
  }
  return WantedFormUID;
}

If you'll only allow one instance of your window, you need to check if your is already in the Forms collection. Like this:


public static bool IsFormOpen(string FormUID, bool SelectIfOpen) {
  int i=0;
  bool found = false;
  Form f;
  while(!found && i<SBO.UI.Connection.SboApplication.Forms.Count) {
  f = SBO.UI.Connection.SboApplication.Forms.Item(i);
  if(f.UniqueID == FormUID) {
    found=true;
    if(SelectIfOpen) {
      if (!f.Selected) {
        SBO.UI.Connection.SboApplication.Forms.Item(FormUID).Select();
      }
    }
  }
  else {
    i++;
  }
}
if(found) {
  return true;
}
else {
  return false;
}		
}

former_member192187
Participant
0 Kudos

It's good solution. It's run

Thank You very much Rasmus

regards

Krzysztof Sala

Answers (0)