1. ## Need help

As some of you may know, my current project is a flipping script. It's coming along nicely, but I have a few minor hiccups. I need help with the following 'problem'.

I have some records within my script. One of them is:
Simba Code:
type ItemData = record  ItemName: String;  BuyTime: Integer;  Amount: Integer;  BuyPrice: Integer;  SellPrice: Integer;  BuyBox: Integer;end;

Next I have the a variable for that type:
Simba Code:
ItemArray: array of Itemdata := [...];

Now I want to create a few functions for the 'ItemArray'. For example I would like create something like this:
Simba Code:
procedure ItemArray.deleteIndex(const index : Integer);

But if I make a function like that I get the following error:
Code:
Error: Parent declaration is out of scope
I was going trough the srl library, because this is also done with 'TIntegerArray' (and more). Writing the procedure isn't the problem (just stealing it from Zyt3x, from the TIntegerArray library). But I can't find how to make a procedure from an array (like 'ItemArray.deleteIndex'). I know how to make the procedure from just a So how could I create those procedures?

I hope my question is clear enough.

2. It looks like you're trying to write a procedure for a specific variable rather than a type.
Simba Code:
type itemArray = array of itemData;
Also I believe convention is to put a 'T' before custom types. TItemData, TItemArray, etc.
Last edited by Citrus; 07-06-2016 at 05:20 PM.

3. Originally Posted by Citrus
It looks like you're trying to write a procedure for a specific variable rather than a type.
Simba Code:
type itemArray = array of itemData;
Also I believe convention is to put a 'T' before custom types. TItemData, TItemArray, etc.
Thanks! I should learn more about the pascal convention. And when I change it to "type itemArray = array of itemData;" I get an error when I'm trying to specify the array (like this: ItemArray := [...].
I get the following error: Error: Target cannot be assigned to.

How should I assign my array? Because an IntegerArray would also be a type, but you can still set it like: I := [1, 2, 3];

4. Simba Code:
typeTItem = record  id: Int32;  end;TItemArray = array of TItem;varItemArray: TItemArray;function TItemArray.Delete(): Boolean;beginend;

5. Originally Posted by Harrier
Simba Code:
typeTItem = record  id: Int32;  end;TItemArray = array of TItem;varItemArray: TItemArray;function TItemArray.Delete(): Boolean;beginend;
Wow thanks! Finally, after a few massive headaches from thinking too hard, I understand it. Thanks both!!

6. Originally Posted by SlipperyPickle
Thanks! I should learn more about the pascal convention. And when I change it to "type itemArray = array of itemData;" I get an error when I'm trying to specify the array (like this: ItemArray := [...].
I get the following error: Error: Target cannot be assigned to.

How should I assign my array? Because an IntegerArray would also be a type, but you can still set it like: I := [1, 2, 3];
I think you already figured it out from Harrier's post, but do you see how you're treating ItemArray and TIntegerArray differently?
You correctly used variable 'I' to assign the int array, but you don't have a variable for your item array. You're basically trying to do: TIntegerArray := [1, 2, 3]; But with ItemArray.
You can see why it helps to use TItemArray as the type

7. Originally Posted by Citrus
I think you already figured it out from Harrier's post, but do you see how you're treating ItemArray and TIntegerArray differently?
You correctly used variable 'I' to assign the int array, but you don't have a variable for your item array. You're basically trying to do: TIntegerArray := [1, 2, 3]; But with ItemArray.
You can see why it helps to use TItemArray as the type
Yeah, took me some time to understand it. Now that I get it, I feel dumb about how I tried to figure it out :P

Both, thanks again for your help! Learned a lot.