Delphi Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Owam
    New Member
    • Mar 2009
    • 2

    #1

    Delphi Array

    Good day, i am getting an error from this piece of code, can you please assist. Error says "Number of element differs from declarations "

    Your assistance will be appreciated. thank you

    here is the code:

    unit Unit1;

    interface

    type
    TUnit1 = record
    ServerName :char;
    ServerPort :integer;
    ActiveFlag :boolean;
    end;
    const
    Servers : array[boolean] of string =
    ('inf1', 'inf_15','inf_1 8',
    'inf_22', 'inf_21', 'inf_20',
    'inf_23', 'inf_26', 'inf_25', 'inf_24');
    Last edited by debasisdas; Mar 26 '09, 11:57 AM. Reason: moved to misc questions forum.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    If you want to index an array with a boolean type the array can have only two elements: one element for the 'false' index value and one for 'true'. You try to initialize it with ten elements; that's what the compiler is whining about.

    kind regards,

    Jos (<--- knows zilch about Delphi)

    Comment

    • Owam
      New Member
      • Mar 2009
      • 2

      #3
      Thank you for your response. I actually found a solution to my problem. it should be as follows:

      type
      TUnit1 = record
      ServerName :string;
      ServerPort :integer;
      ActiveFlag :boolean;
      end;
      const
      Servers : array[0..9] of TUnit1 =
      ((ServerName :'inf1', ServerPort :125, ActiveFlag :false); (ServerName :'inf_15',Serve rPort :125, ActiveFlag :false); (ServerName :'inf_18',Serve rPort :125, ActiveFlag :false);
      (ServerName :'inf_22', ServerPort :125, ActiveFlag :false); (ServerName :'inf_21',Serve rPort :125, ActiveFlag :false); (ServerName :'inf_20',Serve rPort :125, ActiveFlag :false);
      (ServerName :'inf_23',Serve rPort :125, ActiveFlag :false); (ServerName :'inf_26',Serve rPort :125, ActiveFlag :false); (ServerName :'inf_25',Serve rPort :125, ActiveFlag :false); (ServerName :'inf_24',Serve rPort :125, ActiveFlag :false) );

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        That makes sense: now you're indexing your array with an integer range 0 ... 9; you also changed the type of your array elements. Good luck.

        kind regards,

        Jos

        Comment

        Working...