Results 1 to 6 of 6

Thread: Merging two arrays of type string

  1. #1
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Merging two arrays of type string

    Okay, here's my procedure:

    SCAR Code:
    function MergeArrays(var arr1, arr2 : array of string) : array of string;
    var
      i, ii, L1, L2 : integer;
    begin
      Result := arr1;
      L1 := getarraylength(arr1);
      L2 := getarraylength(arr2);
      ii := 0;
      setarraylength(Result, L1 + L2);
      for i := L1 to L2 do
      begin
        Result[i] := arr2[ii];
        ii := ii + 1;
        status(inttostr(ii)); //Debug purposes
      end;
    end;

    What am I doing wrong? I'm trying to merge two arrays into one combined one, but somehow I always crash SCAR when I run this one. Scar just gives me a hex dump and then closes if the array has more than one element.

    Someone help pl0x? I'm getting real frustrated . Having to open SCAR again pisses me OFF. Save all work before trying this.

    It's been a while... but I'm BACK!!!

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function AddTPA(First,Second:array of tpoint):array of tpoint;
    var length1,length2,pArray:integer;
    begin
      length1:=getarraylength(first);
      setarraylength(result,length1);
      result:=first;
      length2:=getarraylength(second);
      setarraylength(result,(length1+length2));
      for pArray:=length1 to (length1+length2-1) do
      begin
        result[parray]:=second[parray-length1];
      end;
    end;

    This worked for me.


    Edit:
    SCAR Code:
    program WTF_IS_WRONG_WITH_SCAR;

    var
      foo, bar, foobar : array of string;

    function MergeArrays(First,Second:array of string):array of string;
    var length1,length2,pArray:integer;
    begin
      length1:=getarraylength(first);
      setarraylength(result,length1);
      result:=first;
      length2:=getarraylength(second);
      setarraylength(result,(length1+length2));
      for pArray:=length1 to (length1+length2-1) do
      begin
        result[parray]:=second[parray-length1];
      end;
    end;


    procedure PutSomethingIntoFooBar;
    begin
      setarraylength(foo, 3);
      foo[0] := 'foo';
      foo[1] := 'foo';
      foo[2] := 'foo';
      setarraylength(bar, 3);
      bar[0] := 'bar';
      bar[1] := 'bar';
      bar[2] := 'bar';
    end;

    procedure writearray(var arr : array of string);
    var
      i : integer;
    begin
      for i := 0 to getarraylength(arr) - 1 do
      Writeln(arr[i]);
    end;

    begin
      PutSomethingIntoFooBar;
      Foobar := MergeArrays(foo, bar);
      WriteArray(foobar);
    end.

    This is weird. It worked once, and then run again and I get the error. Then reopen SCAR and the same thing happens.

    Edit:
    SCAR Code:
    PutSomethingIntoFooBar;
      Setarraylength(foobar,6);
      Foobar := MergeArrays(foo, bar);
      WriteArray(foobar);
    makes it work several times before error

  3. #3
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This sure is very strange... Just one question, is this because of my array merging procedure or is it because I write it to the debug window?

    It's been a while... but I'm BACK!!!

  4. #4
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    It's not the writeln, because taking that out still gives the error. My proc works for TPAs, I don't know why changing it to strings would give an error. So perhaps its how the arrays are started.

  5. #5
    Join Date
    Oct 2006
    Location
    I'm a figment of your imagination
    Posts
    422
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Probably a malformed or misinterpreted type definition as far as my guess goes. So you're saying it's SCAR's fault or is it an error in my script?

    It's been a while... but I'm BACK!!!

  6. #6
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Perhaps SCARs, as this works

    SCAR Code:
    program WTFISWRONGWITHSCAR;

    var
      foo, bar:array of integer;
      foobar : array of integer;

    function MergeArrays(First,Second:array of integer):array of integer;
    var length1,length2,pArray:integer;
    begin
      length1:=getarraylength(first);
      setarraylength(result,length1);
      result:=first;
      length2:=getarraylength(second);
      setarraylength(result,(length1+length2));
      for pArray:=length1 to (length1+length2-1) do
      begin
        result[parray]:=second[parray-length1];
      end;
    end;


    procedure PutSomethingIntoFooBar;
    begin
      setarraylength(foo, 3);
      foo[0] := 1;
      foo[1] := 2;
      foo[2] := 3;
      setarraylength(bar, 3);
      bar[0] := 4;
      bar[1] := 5;
      bar[2] := 6;
    end;

    procedure writearray(var arr : array of integer);
    var
      i : integer;
    begin
      for i := 0 to getarraylength(arr) - 1 do
        Writeln(inttostr(arr[i]));
    end;

    begin
      PutSomethingIntoFooBar;
      Foobar := MergeArrays(foo, bar);
      WriteArray(foobar);
    end.

    But this
    SCAR Code:
    program WTFISWRONGWITHSCAR;

    var
      foo, bar:array of string;
      foobar : array of string;

    function MergeArrays(First,Second:array of string):array of string;
    var length1,length2,pArray:integer;
    begin
      length1:=getarraylength(first);
      setarraylength(result,length1);
      result:=first;
      length2:=getarraylength(second);
      setarraylength(result,(length1+length2));
      for pArray:=length1 to (length1+length2-1) do
      begin
        result[parray]:=second[parray-length1];
      end;
    end;


    procedure PutSomethingIntoFooBar;
    begin
      setarraylength(foo, 3);
      foo[0] := '1';
      foo[1] := '2';
      foo[2] := '3';
      setarraylength(bar, 3);
      bar[0] := '4';
      bar[1] := '5';
      bar[2] := '6';
    end;

    procedure writearray(var arr : array of string);
    var
      i : integer;
    begin
      for i := 0 to getarraylength(arr) - 1 do
        Writeln(arr[i]);
    end;

    begin
      PutSomethingIntoFooBar;
      Foobar := MergeArrays(foo, bar);
      WriteArray(foobar);
    end.

    gives
    SCAR Code:
    RSC font has been loaded
      19.01.2007

    Believe it or not but there is a new SCAR version almost ready.
    More information: [url]http://villu-reborn.com/showthread.php?t=5996[/url]



    Successfully compiled
    1
    2
    3
    4
    5
    6
    Successfully executed
    Successfully compiled
    1
    2
    3
    4
    5
    6
    Successfully executed
    Successfully compiled
    1
    2
    3
    4
    5
    6
    Successfully executed
    Successfully compiled
    1


    4
    5
    6
    Successfully executed
    Successfully compiled
    1
    2
    3
    4
    5
    6
    Successfully executed
    Successfully compiled
    1
    2
    [Runtime Error] : Exception: Access violation at address 00404F04 in module 'scar.exe'. Read of address FFFFFF85 in line 39 in script

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Merging Accounts?
    By Daniel in forum SRL Site Discussion
    Replies: 3
    Last Post: 08-04-2008, 08:07 AM
  2. Arrays, stuck on arrays
    By Camaro' in forum OSR Help
    Replies: 1
    Last Post: 03-08-2008, 02:02 AM

Posting Permissions

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