SRL Archive - OSR Help

Adding tPoint to tpointArray


xdarkshadowx

2012-12-30 21:05:43

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.

DannyRS

2012-12-30 21:09:10

Whats wrong with your other thread :O ? ;)

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

xdarkshadowx

2012-12-30 21:18:30

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..

xdarkshadowx

2012-12-30 21:20:28

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

DannyRS

2012-12-30 21:40:17

From: xdarkshadowx
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 ;)

Wardancer

2012-12-30 22:15:10

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:

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:

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:

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.

nielsie95

2012-12-31 14:01:50

Try using the + operator:


var
a: TPointArray;
b: TPoint;
begin
a := a + TPointArray([b]);
WriteLn(a);
end.

unknownrpg

2012-12-31 16:56:38

From: xdarkshadowx
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

J J

2012-12-31 17:23:52

From: nielsie95
Try using the + operator:


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.

riwu

2012-12-31 20:09:05

From: nielsie95
Try using the + operator:


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…

Brandon

2012-12-31 20:14:59

From: J J
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.