TextProgram.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:3k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "TextProgram.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Form1->Button1->Enabled=true;
- Form1->Button2->Enabled=false;
- Form1->Button3->Enabled=false;
- Form1->Button4->Enabled=false;
- //设置按钮有效性
- Form1->Memo1->Clear();
- //清除文本框
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- if (Form1->OpenDialog1->Execute())
- //显示对话框
- {
- Form1->Button2->Enabled=true;
- Form1->Button3->Enabled=true;
- Form1->Button4->Enabled=true;
- //设置按钮有效状态
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Form1->Memo1->Lines->LoadFromFile(Form1->OpenDialog1->FileName);
- //显示文件内容
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- if (Form1->Memo1->Modified)
- //判断文件是否被改变
- {
- if (MessageDlg("文件已经被修改过,存储修改后的结果吗?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
- //提示用户是否保存修改结果
- {
- if (Form1->SaveDialog1->Execute())
- //显示对话框
- {
- Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
- //存储文件
- }
- }
- }
- Form1->Memo1->Clear();
- //清除文本框中的内容
- Form1->Button2->Enabled=false;
- Form1->Button3->Enabled=false;
- Form1->Button4->Enabled=false;
- //设置按钮有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- Form1->SaveDialog1->Title="请存储为一个文本文件:";
- //设置对话框标题
- Form1->SaveDialog1->Filter="Text Files(*.txt)|*.txt";
- //设置过滤器
- if (Form1->SaveDialog1->Execute())
- //显示对话框
- {
- Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
- //存储文件
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
- {
- if (Form1->Memo1->Modified)
- //判断文件是否被改变
- {
- if (MessageDlg("文件已经被修改过,存储修改后的结果吗?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
- //提示用户是否保存修改结果
- {
- if (Form1->SaveDialog1->Execute())
- //显示对话框
- {
- Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
- //存储文件
- }
- }
- }
- }
- //---------------------------------------------------------------------------