Results 1 to 7 of 7

Thread: TstringArray to TIntegerArray

  1. #1
    Join Date
    Mar 2011
    Location
    Somerset, UK
    Posts
    304
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default TstringArray to TIntegerArray

    Ihave a value in a TstringArray like this

    The TStringArray is OBST
    so

    OBST[i][0] has a value from an ini of: 3235182,3244322 and are colours
    how can i turn this into the TIntegerArray that FindColorEx expects ?

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Why don't you just declare it a TIntegerArray from the start and populate it using StrToInt? :P

    You'll have to create a whole new one for this.
    Simba Code:
    var
      OldArr : TStringArray;
      NewArr : TIntegerArray;
      i, h : integer;
    begin
      OldArr := ['12', '34', '56', '78'];
      h := high(OldArr);
      SetArrayLength(NewArr, h + 1);
      for i := 0 to h do
        NewArr[i] := StrToIntDef(OldArr[i], -1);
      OldArr := [];
    end.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Mar 2011
    Location
    Somerset, UK
    Posts
    304
    Mentioned
    0 Post(s)
    Quoted
    24 Post(s)

    Default

    Perfect thanks

  4. #4
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Can't you use TVariantArray for this?

    ~Home

  5. #5
    Join Date
    May 2006
    Location
    Australia
    Posts
    370
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Variants have types. So it remains as a string. (unless I'm mistaken)
    Best thing to do would be read it in using intToStr straight away, and bypass the string array completely (as sex said).
    ------
    Strong Holder
    Kill Goblins and Zombies in (ex) bot free zones. Loot & Bank. Stable: 1.2b

  6. #6
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Quote Originally Posted by Iamadam View Post
    Variants have types. So it remains as a string. (unless I'm mistaken)
    Best thing to do would be read it in using intToStr straight away, and bypass the string array completely (as sex said).
    Simba Code:
    program new;
    var
      ReqArr : TVariantArray;
      i, h : integer;
    begin
    ReqArr := [12, 34, 56, 78];
    For i := 0 to High(ReqArr) do
      Writeln(ReqArr[i]);
    end.

    Tell me if i'm totally off road :P

    ~Home

  7. #7
    Join Date
    May 2006
    Location
    Australia
    Posts
    370
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ah look at that it does work How awesome!
    Code:
    program new;
    var
      ReqArr : TVariantArray;
      i, h : integer;
    begin
    ReqArr := ['123', '343', '563', '78'];
    For i := 0 to High(ReqArr) do
      Writeln(toStr(ReqArr[i] + 1));
    end.
    I was thinking Java. You can store anything in an 'Object' (equivalent of Variant), but it keeps its type (so you can't add strings to ints or anything).

    Useful.
    ------
    Strong Holder
    Kill Goblins and Zombies in (ex) bot free zones. Loot & Bank. Stable: 1.2b

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •