2012年1月6日 星期五

Write ini with TIniFile

#include "IniFiles.hpp"


void __fastcall TMain::Config1Click(TObject *Sender)
{
    //config setting
    if (FrmConfig->ShowModal() == mrOk)
    {
        try
        {
            String iniDirPath = ExtractFilePath(Application->ExeName)+ "\Config.ini";//ini data path
            TIniFile *aIniFile = new TIniFile(iniDirPath);
            aIniFile->WriteString("Path","SharePath",FrmConfig->edtPort->Text);
            aIniFile->WriteString("Port","ComunicationPort",FrmConfig->edtPath->Text);
        }
        catch(...)
        {
            ShowMessage("Save Config Data Fail!");
        }
    }
}

A dialog for choice catalog path in BCB


void __fastcall TMain::btnChoicePathClick(TObject *Sender)
{
    String Dir=edtPath->Text;
    //SelectDirectory(Dir,TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,0);
    SelectDirectory(Dir,"",Dir);
    edtPath->Text=Dir;
}







limited TEdit key in 0~9 and value in BCB

//limited 0~9 and value < 65535 in BCB
void __fastcall TMain::edtPortKeyPress(TObject *Sender, char &Key)
{
     if (((Key >= '0') && (Key <= '9')) || (Key == '\b'))
     {
        if ((Key >= '0') && (Key <= '9'))
        {
            if (StrToInt(edtPort->Text+Key) > 65535)
                Key = 0;
        }
     }
     else
     {
        Key = 0;
     }
}