BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stream troubles

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
b
Guest





PostPosted: Wed Jul 30, 2003 5:46 pm    Post subject: Stream troubles Reply with quote



i save a ownership file in this way:
from ->position = 0 to ->position = 20 there is a word, then from 21 to 24 a
number.
now using this code i want get the word inside the first 20 sectors of the
file and save it inside a AnsiString, then get the number and save it inside
a int var. For example this is the code i want use to get the number:

void __fastcall TForm1::OpenProjectClick(TObject *Sender)
{
if(OpenDialog1->Execute() == mrOk)
{
Label1->Caption = EncodeNumber(OpenDialog1->FileName);
}
}
//--------------------------------------------------------------------------
-

AnsiString __fastcall TForm1::EncodeNumber(AnsiString ProjectOpenPath)
{
std::auto_ptr<TFileStream> EncStream(new TFileStream(ProjectOpenPath,
fmOpenRead));
EncStream->Position = 20;
TMemoryStream* NumberStream = new TMemoryStream();
NumberStream->Position = 0;
EncStream->Read(NumberStream, 24);
std::auto_ptr<AnsiString> giveNumber(new AnsiString);
giveNumber = NumberStream;
return giveNumber;
}
//--------------------------------------------------------------------------
-

[C++ Error] Program.cpp(931): E2285 Could not find a match for
'auto_ptr<AnsiString>::operator = <_Tp1>(TMemoryStream *)'
[C++ Error] Program.cpp(932): E2285 Could not find a match for
'AnsiString::operator =(auto_ptr<AnsiString>)'







Back to top
b
Guest





PostPosted: Wed Jul 30, 2003 6:10 pm    Post subject: Re: Stream troubles Reply with quote



i have found this
http://deadlock.et.tudelft.nl/~fpc/docs-html/fcl/classes/tstream.writeansist
ring.html but it don't exist in my TStream class


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jul 30, 2003 8:06 pm    Post subject: Re: Stream troubles Reply with quote




"b" <borland.public.cppbuilder.vcl.components.using> wrote


Quote:
AnsiString __fastcall TForm1::EncodeNumber(AnsiString ProjectOpenPath)

That code is not doing what you think it should be doing. See below.

Quote:
EncStream->Read(NumberStream, 24);

You are telling the file to read 24 bytes into the memory stream, not to
read the file to position 24.

Quote:
std::auto_ptr<AnsiString> giveNumber(new AnsiString);

There is no need to dynamically alocate an AnsiString in this situation.

Quote:
giveNumber = NumberStream;

You are trying to assign a TMemoryStream* to an auto_ptr that already
contains an AnsiString*.

Quote:
return giveNumber;

You are trying to return an auto_ptr as an AnsiString.

If all you are trying to do is retreive the number from the file, then your
current code is very overkill let alone non-functional anyway. Just do the
following instead:

AnsiString __fastcall TForm1::EncodeNumber(AnsiString ProjectOpenPath)
{
int i = 0;
std::auto_ptr<TFileStream> EncStream(new
TFileStream(ProjectOpenPath, fmOpenRead));
EncStream->Position = 21;
EncStream->ReadBuffer(&i, 4);
return i;
}


Gambit




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jul 30, 2003 8:07 pm    Post subject: Re: Stream troubles Reply with quote


"Liz Albin" <lizalbin (AT) yahooNotThis (DOT) com> wrote


Quote:
have you tried: EncStream->get()

That should be '.', not '->':

EncStream.get()

Not that it means anything though since the code was trying to assign an
TMemoryStream to an auto_ptr that already contained an AnsiString, which is
wrong.


Gambit




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jul 30, 2003 8:10 pm    Post subject: Re: Stream troubles Reply with quote


"b" <borland.public.cppbuilder.vcl.components.using> wrote

Quote:
i have found this

http://deadlock.et.tudelft.nl/~fpc/docs-html/fcl/classes/tstream.writeansist
ring.html but it don't exist in my TStream class

That has nothing to do with the VCL at all. That is for a completely
different third-party library called FCL (Free Component Library) that is
for the FreePascal compiler. The library is written to have similar
syntaxes as the VCL, but do not confuse it as being the VCL, because it is
not at all.


Gambit




Back to top
b
Guest





PostPosted: Wed Jul 30, 2003 10:51 pm    Post subject: Re: Stream troubles Reply with quote

well, i can run the program, but when i try to Open and read with your
method i get the follow number 8912928 at the place of a simple 2.
Why?

Futhermore if i want read a string of characters for example from the
position 25 at 42, and save it in AnsiString how can i do?







Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jul 30, 2003 11:14 pm    Post subject: Re: Stream troubles Reply with quote


"b" <borland.public.cppbuilder.vcl.components.using> wrote

Quote:
well, i can run the program, but when i try to Open and
read with your method i get the follow number 8912928
at the place of a simple 2.
Why?

Please show your actual file data. What exactly does it look like, and what
exactly are you trying to read from it?

Quote:
Futhermore if i want read a string of characters for
example from the position 25 at 42, and save it in
AnsiString how can i do?

You have two options:

1) declare an AnsiString, call its SetLength() method, and then pass its
c_str() pointer to the stream's Read() method.

1) Use a TStringStream instead, read the file data into the stream, then you
can access the DataString property after the read.


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.