C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[54081] Re:TPersistent 관해서
장성호 [nasilso] 1410 읽음    2008-07-24 18:54
"Test.txt" 파일이 없어서 그런것 같은데요


TFileStream  생성 옵션 입니다.  참조하세요

fmCreate    Create a file with the given name. If a file with the given name exists, open the file in write mode.
fmOpenRead    Open the file for reading only.
fmOpenWrite    Open the file for writing only. Writing to the file completely replaces the current contents.
fmOpenReadWrite    Open the file to modify the current contents rather than replace them.


fmCreate 파일이 있으면 쓰기용으로 열고, 없으면 만듭니다.
fmOpenRead 파일을 읽기만 가능하게 엽니다.
fmOpenWrite 파일을 쓰기만 가능하게 엽니다.
fmOpenReadWrite 파일을 읽고 쓸수 있게 엽니다

그럼..


초보자 님이 쓰신 글 :
: 안녕하세요 TPersisternt  차트 공부하다가 Button1 을 누를때 memo1에 소스가 기록되서 나오고
:  Button2 누를때 memo2를 소스를 test.txt에 기록하고 마지막으로 Button3 누를 시 문자 'A'라는 글자를 Test.txt의 맨
: 앞부분에 붙이는 역할 수행 하는 소스 예제를 쳐봤는데요
:
: 우선 Button1 누르는건 실행이 되지만 Button2 누르거나 Button3 누르면 test.txt cannot open 매세지 출력하게 되네요
: 먼가 문제 있는지 확인 부탁드립니다
:
:
: <소스>
:
: //---------------------------------------------------------------------------
:
: #include <vcl.h>
: #pragma hdrstop
:
: #include "TPersistent1.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
:     : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: TMemoryStream *theMemStream;
: theMemStream = new TMemoryStream;
:  try{
:    //파일을 로드한다
:   theMemStream->LoadFromFile("TPersMain.cpp");
:    //42째 문자의 위치를 찾는다
:    theMemStream->Seek(0,soFromBeginning);
:    //스트림으로부터 그문자를 불러온다
:    Memo1->Lines->LoadFromStream(theMemStream);}
:    __finally {delete theMemStream;}
:
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button2Click(TObject *Sender)
: {
: TFileStream *theFileStream;
: theFileStream = new TFileStream("Test.txt",fmOpenWrite);
: Memo1->Lines->SaveToStream(theFileStream);
: delete theFileStream;
:    
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button3Click(TObject *Sender)
: {
: char theChar='A';
: TMemoryStream *m;
: m = new TMemoryStream;
: m->WriteBuffer(&theChar,sizeof(char));
: TFileStream* f = new TFileStream("Test.txt",fmOpenRead);
: m->CopyFrom(f , f->Size);
: delete f;
: m ->SaveToFile("Test.txt");
:
: }
:
:
: 자세한 설명 부탁드립니다 그리고 중요한부분이거나 공부해야 할 참고사항 주석으로 달아주시면 좋은정보로 쓸께요
:
: 항상 좋은 정보 감사합니다

+ -

관련 글 리스트
54076 TPersistent 관해서 초보자 1422 2008/07/24
54081     Re:TPersistent 관해서 장성호 1410 2008/07/24
54082         Re:Re:TPersistent 관해서 초보자 1550 2008/07/24
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.