#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    40
    Rep Power
    11

    [C++ Builder 6.0] Streams and TInifiles


    Hi, I have a problem where I have to save the data of a graph into a file. Usually I save the inputs, and regenerate the graph from that, but for backward compatibility I need to be able to save all the data as well. I tried

    PHP Code:
      TIniFile *= new TIniFile(filename);
      
    String Data;
      for (
    int i 0Chart->SeriesCounti++)
        for (
    int c 0Chart->Series[i]->Count(); c++)
           
    Data Data IntToStr(Chart->Series[i]->YValues[c].value);
      
    F->WriteString("GraphData",Chart->Series[i]->Title,Data); 
    My problem is that the graph data is longer than 2048 bytes (written in commadelimited string format), so when I read it back, I have lost data. (Looking at the .ini file I can see that the data was written, but when reading it, the string has a 2048 cap).

    Then I looked at TIniFile, and saw the WriteBinaryStream method. So I decided I'll use it.

    What I want to know is, after defining my stream... ie.
    PHP Code:
    TMemoryStream *Data = new TMemoryStream(); 
    How do I add my values (integers) into the Stream?

    I tried
    PHP Code:
       int t = (int)Chart->Series[i]->YValues[c].value;
       
    Data << t
    but it doesn't work.

    Eventually
    PHP Code:
      F->WriteBinaryStream("GraphData",Chart->Series[i]->Title,Data); 
    will be called to save it, and
    PHP Code:
      F->ReadBinaryStream("GraphData",Names[i],Data); 
    will read it again for me.

    Help with how to get it from that stream back to an array of data would also be appreciated.

    Thanks for your help.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Why not just write the data into a regular file using good ol' fopen(), fprintf(), fclose() etc.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    40
    Rep Power
    11
    Well, part of the point is that I want to learn how to use TStreams.

    But I used a string in the end... basically, I took the number lets say 40000, and write it down in base 200. Then each of my numbers are 3 characters long, and wrote all the data like that.

    PHP Code:
          String DataString "";
          for (
    int c 0Chart->Series[i]->Count(); c++)
          {
            
    double t Chart->Series[i]->YValues->Value[c];
            
    int it = (int)t;
            
    char t1 it%200;
            
    char t2 = (it t1)%(200*200)/200;
            
    char t3 = (it t2 t1*200)%(200*200*200)/200/200;
            
    // I add 40, because the first 32 chars are control characters
            
    t1 t1+40;
            
    t2 t2+40;
            
    t3 t3+40;
            
    DataString DataString t1 t2 t3;
          }


    //Decoding  (unsigned was *very* important)
          
    while (S.Length() >= && !done)
          {
            if (
    S.Length() > 3)
              
    S.SubString(4,S.Length());
            else 
    done true;
            
    long t;
            
    unsigned char t1 S[1];
            
    unsigned char t2 S[2];
            
    unsigned char t3 S[3];

            
    = (t1-40)+(t2-40)*256+(t3-40)*256*256;
          } 

IMN logo majestic logo threadwatch logo seochat tools logo