Results 1 to 11 of 11

Thread: Adding tPoint to tpointArray

  1. #1
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default Adding tPoint to tpointArray

    I have a tpoiintArray with a bunch of items in it, let's call it, OriginalArray.
    and I have certain parts of it that I wasn to group together into a new array, called, ArrayOfUsefulStuff. now the problem is I don't know how to take a single tpoint from original array (originalArray[integer]) and add it into the new array, the ArrayOfUseFulStuff.


    short version: trying to add a Tpoint to the end Tpointarray.

  2. #2
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Whats wrong with your other thread :O ?

    http://villavu.com/forum/showthread.php?t=94539


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  3. #3
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    people don't check a help thread once there is a reply, and I didn't get an answer in that reply. so it wasn't going anywhere..

  4. #4
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    And then I realized I don't know how to delete a thread.

  5. #5
    Join Date
    Nov 2012
    Posts
    2,351
    Mentioned
    55 Post(s)
    Quoted
    603 Post(s)

    Default

    Quote Originally Posted by xdarkshadowx View Post
    people don't check a help thread once there is a reply, and I didn't get an answer in that reply. so it wasn't going anywhere..
    If you legitimately need to bump for a related issue, then people will most definetly still reply


    Programming is like trying keep a wall of shifting sand up, you fix one thing but somewhere else starts crumbling

  6. #6
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    I'll answer in roughly 60-90 minutes if no one else does, but for the sake of giving you a complete answer once I have some time, will you need to remove items from the array too (that's a tad more complicated)?

    EDIT: I was genuinely hoping that someone else would answer. This will be a pain to explain. Before answering, I'd like to say that it'd be appreciated by the community if you respected the forum rules, as in avoid double posting (whether it's two threads or two posts). This is needed to avoid littering the forum with unneeded material and, more importantly, to make the search engine more effective for people facing the same issue as you in the future. Now, to the real deal.

    The first thing needed is to be able to enlarge the length of the array to allow you to add new information to it. This can be done with this command:

    Simba Code:
    SetArrayLength(OriginalArray, GetArrayLength(OriginalArray) + 1);

    Now that this is done, you have some place to add information. Based on the complexity of what you want to add, you might decide to write a distinct procedure or leave it to one line. I'll assume that the information is complex and make a distinct procedure for it. You can shorten it for your needs after. Let's call the procedure LoadOriginalArray:

    Simba Code:
    procedure LoadOriginalArray(WhatOriginalArrayTP, WhatArrayOfUsefulStuffTP : integer); //Wouldn't it actually be a TPoint for you, not an integer?
    begin
      OriginalArray[WhatOriginalArrayTP] := ArrayOfUsefulStuff[WhatArrayOfUsefulStuffTP];
    end;

    Note: When it comes to integer, it isn't needed to make a distinct procedure as it is fairly simple and straightforward. However, it isn't that simple when you want to add information to a long record list.

    And, finally, an actual use of the procedure:

    Simba Code:
    procedure EnlargeYourOriginalArray;
    begin
      SetArrayLength(OriginalArray, GetArrayLength(OriginalArray) + 1);
      LoadOriginalArray(high(OriginalArray), high(ArrayOfUsefulStuff));
    end;

    Tadam!

    If you'd like to know how to remove an item from your OriginalArray, feel free to post again. Also, if anything isn't clear, feel free to ask for more details.

  7. #7
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Try using the + operator:

    Simba Code:
    var
      a: TPointArray;
      b: TPoint;
    begin
      a := a + TPointArray([b]);
      WriteLn(a);
    end.
    Hup Holland Hup!

  8. #8
    Join Date
    Apr 2012
    Posts
    113
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by xdarkshadowx View Post
    And then I realized I don't know how to delete a thread.
    sry i dont know how to fix ur prob very limited sciptin knowledge here, and i dont mean to mooch off ur thread but can we delete threads we start =?
    ive got a couple myself that could use deleting

  9. #9
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Try using the + operator:

    Simba Code:
    var
      a: TPointArray;
      b: TPoint;
    begin
      a := a + TPointArray([b]);
      WriteLn(a);
    end.
    Dont think an index as TPoint will work.
    SetLength will work as mentioned above.

    Script source code available here: Github

  10. #10
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Try using the + operator:

    Simba Code:
    var
      a: TPointArray;
      b: TPoint;
    begin
      a := a + TPointArray([b]);
      WriteLn(a);
    end.
    Wow never knew you can do that! I always do the 2 steps...

  11. #11
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by J J View Post
    Dont think an index as TPoint will work.
    SetLength will work as mentioned above.
    Lol.. That's not the index operator (well not the way he's using it). That's the array operator. He constructs an array through the TPointArray constructor and the array operator and then appends it using the addition operator which is probably overloaded so it works this way. It's either the constructor or some sort of functor (overloading the () operator).

    In pascal you do arrays using [1, 2, 3, 4, 5].. His code works if you try it.
    Last edited by Brandon; 01-01-2013 at 01:19 AM.
    I am Ggzz..
    Hackintosher

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
  •