Results 1 to 7 of 7

Thread: Need help

  1. #1
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

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

    Thanks in advance!

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    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. #3
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    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. #4
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Simba Code:
    type
    TItem = record
      id: Int32;
      end;
    TItemArray = array of TItem;
    var
    ItemArray: TItemArray;

    function TItemArray.Delete(): Boolean;
    begin
    end;
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  5. #5
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Harrier View Post
    Simba Code:
    type
    TItem = record
      id: Int32;
      end;
    TItemArray = array of TItem;
    var
    ItemArray: TItemArray;

    function TItemArray.Delete(): Boolean;
    begin
    end;
    Wow thanks! Finally, after a few massive headaches from thinking too hard, I understand it. Thanks both!!

  6. #6
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by SlipperyPickle View Post
    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. #7
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    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.

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
  •