-
[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 *F = new TIniFile(filename);
String Data;
for (int i = 0; i < Chart->SeriesCount; i++)
for (int c = 0; c < Chart->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.
-
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
July 12th, 2004, 01:26 AM
-
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 = 0; c < Chart->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() >= 3 && !done)
{
if (S.Length() > 3)
S = 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];
t = (t1-40)+(t2-40)*256+(t3-40)*256*256;
}