Results 1 to 4 of 4

Thread: A Map Editor Question

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Location
    19¬? 44′ 52″ S, 47¬? 55′ 55″ W
    Posts
    4

    A Map Editor Question

    Hello PGD users.

    When I Has making my Map Editor i encoutred a really strange error on my MapEd the map can't be opened
    It appears a message showing : '' is not a valid integer value can anyone help me with this?


    Here is the code for opening and Saving and The program


    Opening:
    Code:
    procedure TForm1.Button5Click(Sender: TObject);
    var
    Arquivo : TextFile;
    X, Y : Integer;
    Temp: String;
    begin
    if OpenDialog1.Execute then
     begin
      AssignFile(Arquivo,OpenDialog1.FileName);
      Reset(Arquivo);
       for X:= 0 to 9 do
        begin
          ReadLn(Arquivo, Temp);
          for Y := 0 to 9 do
            Area[Y, X] := StrToInt(Copy(Temp, Y + 1, 1))
        end;
        CloseFile(Arquivo);
        DrawGrid1.Refresh;
      end;
    end;
    For Saving
    Code:
    procedure TForm1.Button4Click(Sender: TObject);
    var
     Arquivo : TextFile;
     X,Y : Integer;
     S : string;
    begin
     if SaveDialog1.Execute then
      begin
       AssignFile(Arquivo,SaveDialog1.FileName);
       Rewrite(Arquivo);
        for X:= 0 to 9 do
        begin
         for Y:= 0 to 9 do
          S:= S + IntToStr(Area[Y,X]);
         WriteLn(Arquivo,S);
         S:='';
       end;
       CloseFile(Arquivo);
    end;
    end;
    Can anyone help me with this ?
    THX

    mongoixp

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    Hi mongoixp,

    The problem is, I believe, the fact that you aren't marking the end of one integer in your string, so StrToInt is interpreting the whole string as one big integer which will result in an error.

    What you could do is this:-

    Code:
    var
     f : file of integer;
     x,y : integer;
    begin
     assignFile(f,saveDialog1.filename);
     rewrite(f);
     for x:=0 to 9 do
     begin
      for y:=0 to 9 do
      begin
       write(f,area[x,y]);
      end;
     end;
     closefile(f);
    end;
    Of course this does mean the file can only store integers... may not be what you want. So, you could look at introducing some formatting to your string based file...

    If the values in the area array are only going to be 16 bit values, you could do this:-

    Code:
    For writing:-
    
    for x:=0 to 9 do
    begin
     s:='';
     for y:=0 to 9 do
     begin
      s:=s+intToHex(area[x,y],4);
     end;
     writeln(arquivo,s);
    end;
    
    And then for reading:-
    
    for x:=0 to 9 do
    begin
     readln(arquivo,s);
     for y:=0 to 9 do
     begin
      area[x,y]:=intToStr('$'+copy(s,y*4,4));
     end;
    end;
    And if you want to store a variety of information, you could use streams... a good starting point would be my article on versioned data storage as it presents streams and the concepts of versioning your data store, plus it has a fairly good example of using it as a map store (it's how I store my maps). The article can be found here.

    Hope this helps.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    Ignore my comment about what I think the problem is... I just re-read your code and now, I'm not sure

    Actually, scratch that too... just noticed something...

    Code:
    for X:= 0 to 9 do
    begin
     for Y:= 0 to 9 do
      S:= S + IntToStr(Area[Y,X]);
     WriteLn(Arquivo,S);
     S:='';
    end;
    The line S:=''; should really be before the 'y' for loop. As it is, S could contain anything. Now I'm not sure how this would cause your problem unless you were unlucky and say got an end of file marker or something like that in there.

    The other thing I mentioned in my original reply was about the lengths of the strings being written out. What happens if one the values you're writing is bigger than 9? At the moment, it appears that this code won't work properly.

    Anyhow, if I can be of any further confusion, please don't hesitate to ask
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Location
    19¬? 44′ 52″ S, 47¬? 55′ 55″ W
    Posts
    4
    HI, Now i know why pop up the error message " '' is not a valid integer value" in my original source code i put a wrong nunber in the lines of
    Code:
    for x:=0 to 29
    and
    y:=0 to 29
    My array is 0 to 9

    Anyway thanks AthenaofDelphi for aswering my post.

Bookmarks

Posting Permissions

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