paritytypesele.cpp

来自「串口调试工具」· C++ 代码 · 共 79 行

CPP
79
字号
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "ParityTypeSele.h"
//--------------------------------------------------------------------- 
#pragma link "cspin"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TChooseParity *ChooseParity;
//---------------------------------------------------------------------
__fastcall TChooseParity::TChooseParity(TComponent* AOwner)
	: TForm(AOwner)
{
  CRCBits->ItemIndex = 0;
  Initial->ItemIndex = 0;
  FinalMask->ItemIndex = 0;    
  TIniFile *pIni = OpenIniFile();
  CRCScheme->Clear();
  pIni->ReadSections(CRCScheme->Items);
  delete pIni;
}
//---------------------------------------------------------------------

void __fastcall TChooseParity::CRCBitsChange(TObject *Sender)
{
  if ( CRCBits->ItemIndex >= 0 )  {
    String a = "FFFFFFFFFF";
    a = a.SubString(1, CRCBits->Text.ToInt()/8*2);
    int i = Initial->ItemIndex;
    Initial->Items->Strings[1] = a;
    Initial->ItemIndex = i;
    i = FinalMask->ItemIndex;
    FinalMask->Items->Strings[1] = a;
    FinalMask->ItemIndex = i;
  }
}
//---------------------------------------------------------------------------

void __fastcall TChooseParity::CRCSchemeChange(TObject *Sender)
{
  if ( CRCScheme->Items->IndexOf(CRCScheme->Text) >= 0 )  {
    TIniFile *pIni = OpenIniFile();
    CRCBits->Text = pIni->ReadString(CRCScheme->Text,"BITS","8");
    Polynomial->Text = pIni->ReadString(CRCScheme->Text,"POLYNOMIAL","FF");
    Initial->Text = pIni->ReadString(CRCScheme->Text,"INITIAL","FF");
    FinalMask->Text = pIni->ReadString(CRCScheme->Text,"FINALMASK","FF");
    Reverse->Checked = UpperCase(pIni->ReadString(CRCScheme->Text,"REVERSE","FALSE"))
                       == "TRUE";
    delete pIni;
  }
  SaveScheme->Enabled = !CRCScheme->Text.IsEmpty();
  UseCRC->Checked = true;
}
//---------------------------------------------------------------------------
TIniFile * __fastcall TChooseParity::OpenIniFile(void)
{
  String filename = ExtractFilePath(Application->ExeName)+"\\"+"CRCScheme.ini";
  return new TIniFile(filename);
}
//---------------------------------------------------------------------------

void __fastcall TChooseParity::SaveSchemeClick(TObject *Sender)
{
  TIniFile *pIni = OpenIniFile();
  if ( !pIni->SectionExists(CRCScheme->Text) || ::MessageBox(Handle,
       "方案已经存在,要覆盖吗?","",MB_OKCANCEL|MB_ICONQUESTION)==IDOK )  {
    pIni->WriteString(CRCScheme->Text,"BITS",CRCBits->Text);
    pIni->WriteString(CRCScheme->Text,"POLYNOMIAL",Polynomial->Text);
    pIni->WriteString(CRCScheme->Text,"INITIAL",Initial->Text);
    pIni->WriteString(CRCScheme->Text,"FINALMASK",FinalMask->Text);
    pIni->WriteString(CRCScheme->Text,"REVERSE",(Reverse->Checked)?"TRUE":"FALSE");
    pIni->ReadSections(CRCScheme->Items);
  }
  delete pIni;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?