全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:897
推到 Plurk!
推到 Facebook!

Saving Document changes before closing down.

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-31 14:44:53 IP:61.218.xxx.xxx 未訂閱
Saving Document changes before closing down.     --------------------------------------------------------------------------------    http://www.hobbypages.net/snip19.html    Programs that write data need to keep track of the state of the data, whether it's been saved or not. This routine checks at the request to close the program. It's a simple true/false question. If the data is unsaved, do you want to save it before closing. The boolean declaration goes in the form's header, in the private section.     bool DataIsDirty;// catchy name isn't it?    Then the OnChange event for the TMemo or TRichEdit control can write: DataIsDirty = true;, and the SaveDialog->Execute( ) can write: DataIsDirty = false;. The code will keep track, and if you choose to close while the data is unsaved, it'll prompt you for a choice.  Here's the CloseQuery event handler: 

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
//code for saving on close
if (DataIsDirty == false)
        {
        CanClose = true;
        return;
        }
else
        {
        int ExitCode = Application->MessageBox
        ("Do you want to save this file?", "Before you leave",
        MB_YESNOCANCEL | MB_ICONQUESTION);            switch(ExitCode)
                {
                case IDCANCEL:
                        CanClose = false;
                break;
                case IDYES:
                        CanClose = true;
                        if (SaveDialog1->Execute())
                                {
                                RichEdit->Lines->SaveToFile
                                (SaveDialog1->FileName);
                                }
                break;
                case IDNO:
                         CanClose = true;
                break;
                }
        }
}    
You can use a similar routine assigned to a timer event, to save the changes at a set interval. Just be sure to test for the existence of "FileName" first, in case it's the first time, and a new document. 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
系統時間:2024-05-06 10:42:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!