Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,836 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!




VCL TFileStream

 
Reply to this topicStart new topic

VCL TFileStream, It just wont work

UG Cyber
3 Oct, 2008 - 01:09 PM
Post #1

D.I.C Head
**

Joined: 24 Jul, 2008
Posts: 185



Thanked: 3 times
My Contributions
What i am trying to do is simply organize my contact information on my computer. During the testing of it, i found that the program will not open the file. The error message displayes "EMOpenError- Contacts cannot open List.cont"
Can anyone tell me what i am doing wrong....
Here is the code (Its in GUI using Borland)
cpp


//---------------------------------------------------------------------------

#include <clx.h>
#pragma hdrstop
#include <fstream>

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.xfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::AddContactClick(TObject *Sender)
{
TFileStream *FileStream;
FileStream = new TFileStream("List.Cont",fmOpenWrite);
FileStream->Write("Name: ", strlen("Name: "));
FileStream->Write(ContactName->Text, sizeof(ContactName->Text));
FileStream->Write("\n", sizeof("\n"));
FileStream->Write(Number1Type->Text, sizeof(Number1Type->Text));
FileStream->Write(": ", sizeof(": "));
FileStream->Write(Number1->Text, sizeof(Number1->Text));
FileStream->Write("\n", sizeof("\n"));
FileStream->Write(Number2Type->Text, sizeof(Number2Type->Text));
FileStream->Write(": ", sizeof(": "));
FileStream->Write(Number2->Text, sizeof(Number2->Text));
FileStream->Write("\n\n\n", sizeof("\n\n\n"));

}
//---------------------------------------------------------------------------

void __fastcall TForm1::LoadContactClick(TObject *Sender)
{
ContactsDisplay->Lines->LoadFromFile("List.cont");
}
//----------------


it doesnt display any other warnings or errors in the compilier.

Thanks in advance biggrin.gif
User is offlineProfile CardPM
+Quote Post

UG Cyber
RE: VCL TFileStream
4 Oct, 2008 - 05:53 AM
Post #2

D.I.C Head
**

Joined: 24 Jul, 2008
Posts: 185



Thanked: 3 times
My Contributions
Anyone?? I'm sure its a small stupid mistake....
User is offlineProfile CardPM
+Quote Post

Dunks
RE: VCL TFileStream
18 Nov, 2008 - 12:55 AM
Post #3

New D.I.C Head
*

Joined: 18 Nov, 2008
Posts: 1

QUOTE(UG Cyber @ 4 Oct, 2008 - 05:53 AM) *

Anyone?? I'm sure its a small stupid mistake....

May be u should open File for reading

TFileStream *FileStream = new TFileStream("List.Cont",fmOpenRead);

Besides u should

delete FileStream;

to free up RAM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 04:26PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month