How to: Find type of IPCsList


Topic:

Find type of IPCsList


Class hierarchy:

IPCsLists IPCsList


Description:

To examine a variable of IPCsList , use IPCsList.ListType to get information on what kind of list it is


Sourcecode:
[+] Delphi
uses DPSCAD_TLB;

var
  ListOfUnknown : IPCsList;
  AllLists : IPCsLists;
  i : integer;
  EmptyStr : string;
begin
  {check if we're connected to Automation}
  if CheckConnection() then    // (See function here)
    begin
      {minimize code by getting all lists into variable}
      AllLists := PCsApplication.ActiveDocument.Drawing.Lists;
      Randomize;
      i := random(4);

      {create random list}
      case i of
        0 : ListOfUnknown := AllLists.CreateCableList(EmptyStr);
        1 : ListOfUnknown := AllLists.CreateTerminalList(EmptyStr);
        2 : ListOfUnknown := AllLists.CreatePartList(EmptyStr);   // Not implemented yet!
        3 : ListOfUnknown := AllLists.CreateComponentList(EmptyStr);
      end;

      {find out what type of list, that was created}
      case ListOfUnknown.ListType of
        ltCable : ShowMessage('List is ltCable');
        ltTerm : ShowMessage('List is ltTerm');
        ltPart : ShowMessage('List is ltPart');
        ltComp : ShowMessage('List is ltComp');
      end;
    end;
end;

[+] Visual Basic
Dim ListOfUnknown As Dpscad.PCsList
Dim AllLists As Dpscad.PCsLists
Dim i As Integer = 3
Dim EmptyStr As String = ""

'check if we're connected to Automation
If CheckConnection() Then   // (See function here)
  'minimize code by getting all lists into variable
  AllLists = PCsApplication.ActiveDocument.Drawing.Lists
  'create random list
  Select Case Int((i + 1) * Rnd())
    Case 0
      ListOfUnknown = AllLists.CreateCableList(EmptyStr)
      Exit Select
    Case 1
      ListOfUnknown = AllLists.CreateTerminalList(EmptyStr)
      Exit Select
    Case 2
      ListOfUnknown = AllLists.CreatePartList(EmptyStr)
      'Not implemented yet!
      Exit Select
    Case 3
      ListOfUnknown = AllLists.CreateComponentList(EmptyStr)
      Exit Select
    Case Else
      ListOfUnknown = Nothing
      Exit Select
  End Select

  'find out what type of list, that was created
  Select Case CStr(ListOfUnknown.ListType)
    Case "ltCable"
      MessageBox.Show("List is ltCable")
      Exit Select
    Case "ltTerm"
      MessageBox.Show("List is ltTerm")
      Exit Select
    Case "ltPart"
      MessageBox.Show("List is ltPart")
      Exit Select
    Case "ltComp"
      MessageBox.Show("List is ltComp")
      Exit Select
    Case Else
      MessageBox.Show("Unkown list")
      Exit Select
  End Select
End If

[+] C#
Dpscad.PCsList ListOfUnknown;
Dpscad.PCsLists AllLists;
Random rnd = new Random();
int i = 3;
string EmptyStr = "";

/*check if we're connected to Automation*/
if (CheckConnection())   // (See function here)
{
  /*minimize code by getting all lists into variable*/
  AllLists = PCsApplication.ActiveDocument.Drawing.Lists;

  /*create random list*/
  switch (rnd.Next(i))
  {
    case 0:
      ListOfUnknown = AllLists.CreateCableList(EmptyStr);
      break;
    case 1:
      ListOfUnknown = AllLists.CreateTerminalList(EmptyStr);
      break;
    case 2:
      ListOfUnknown = AllLists.CreatePartList(EmptyStr);   // Not implemented yet!
      break;
    case 3:
      ListOfUnknown = AllLists.CreateComponentList(EmptyStr);
      break;
    default:
      ListOfUnknown = null;
      break;
  }

  /*find out what type of list, that was created*/
  switch (Convert.ToString(ListOfUnknown.ListType))
  {
    case "ltCable":
      MessageBox.Show("List is ltCable");
      break;
    case "ltTerm":
      MessageBox.Show("List is ltTerm");
      break;
    case "ltPart":
      MessageBox.Show("List is ltPart");
      break;
    case "ltComp":
      MessageBox.Show("List is ltComp");
      break;
    default:
      MessageBox.Show("Unkown list");
      break;
  }
}