filterform.cpp

来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 130 行

CPP
130
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FilterForm.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmFilter *frmFilter;

extern USHORT usFHiValue[8],usFLowValue[8],usFEnable;
//---------------------------------------------------------------------------
__fastcall TfrmFilter::TfrmFilter(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmFilter::chkBitEnable1Click(TObject *Sender)
{

    TCheckBox *chkbox = (TCheckBox* )(Sender);
    if(chkbox->Checked){
        if(chkbox == chkBitEnable0){
            txtHiValue0->Enabled = True;
            txtLoValue0->Enabled = True;
        }else if(chkbox == chkBitEnable1){
            txtHiValue1->Enabled = True;
            txtLoValue1->Enabled = True;
        }else if(chkbox == chkBitEnable2){
            txtHiValue2->Enabled = True;
            txtLoValue2->Enabled = True;
        }else if(chkbox == chkBitEnable3){
            txtHiValue3->Enabled = True;
            txtLoValue3->Enabled = True;
        }else if(chkbox == chkBitEnable4){
            txtHiValue4->Enabled = True;
            txtLoValue4->Enabled = True;
        }else if(chkbox == chkBitEnable5){
            txtHiValue5->Enabled = True;
            txtLoValue5->Enabled = True;
        }else if(chkbox == chkBitEnable6){
            txtHiValue6->Enabled = True;
            txtLoValue6->Enabled = True;
        }else{
            txtHiValue7->Enabled = True;
            txtLoValue7->Enabled = True;
        }
    }else{
        if(chkbox == chkBitEnable0){
            txtHiValue0->Enabled = False;
            txtLoValue0->Enabled = False;
        }else if(chkbox == chkBitEnable1){
            txtHiValue1->Enabled = False;
            txtLoValue1->Enabled = False;
        }else if(chkbox == chkBitEnable2){
            txtHiValue2->Enabled = False;
            txtLoValue2->Enabled = False;
        }else if(chkbox == chkBitEnable3){
            txtHiValue3->Enabled = False;
            txtLoValue3->Enabled = False;
        }else if(chkbox == chkBitEnable4){
            txtHiValue4->Enabled = False;
            txtLoValue4->Enabled = False;
        }else if(chkbox == chkBitEnable5){
            txtHiValue5->Enabled = False;
            txtLoValue5->Enabled = False;
        }else if(chkbox == chkBitEnable6){
            txtHiValue6->Enabled = False;
            txtLoValue6->Enabled = False;
        }else{
            txtHiValue7->Enabled = False;
            txtLoValue7->Enabled = False;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmFilter::btnOKClick(TObject *Sender)
{

    usFEnable = 0;
    TCheckBox* chbox[8] = {chkBitEnable0,chkBitEnable1,chkBitEnable2,chkBitEnable3,chkBitEnable4,chkBitEnable5,chkBitEnable6,chkBitEnable7};
    TEdit* txtHi[8] = {txtHiValue0,txtHiValue1,txtHiValue2,txtHiValue3,txtHiValue4,txtHiValue5,txtHiValue6,txtHiValue7};
    TEdit* txtLo[8] = {txtLoValue0,txtLoValue1,txtLoValue2,txtLoValue3,txtLoValue4,txtLoValue5,txtLoValue6,txtLoValue7};
    for(int i=0; i < 8; i++){
        if(chbox[i]->Checked){
            usFEnable |= (0x01<<i);
            usFHiValue[i] = txtHi[i]->Text.ToDouble();
            usFLowValue[i] = txtLo[i]->Text.ToDouble();
        }else{
            usFEnable &= ~(0x01<<i);
            usFHiValue[i] = 0;
            usFLowValue[i] = 0;
        }
    }
    this->Close();
}
//---------------------------------------------------------------------------


void __fastcall TfrmFilter::btnCancelClick(TObject *Sender)
{
    this->Close();
}
//---------------------------------------------------------------------------



void __fastcall TfrmFilter::FormShow(TObject *Sender)
{
    TCheckBox* chbox[8] = {chkBitEnable0,chkBitEnable1,chkBitEnable2,chkBitEnable3,chkBitEnable4,chkBitEnable5,chkBitEnable6,chkBitEnable7};
    TEdit* txtHi[8] = {txtHiValue0,txtHiValue1,txtHiValue2,txtHiValue3,txtHiValue4,txtHiValue5,txtHiValue6,txtHiValue7};
    TEdit* txtLo[8] = {txtLoValue0,txtLoValue1,txtLoValue2,txtLoValue3,txtLoValue4,txtLoValue5,txtLoValue6,txtLoValue7};

    for(int i=0; i<8; i++){
        if(usFEnable & (USHORT)pow(2,i)){
            chbox[i]->Checked = True;
            txtHi[i]->Enabled = True;
            txtLo[i]->Enabled = True;
            txtHi[i]->Text = AnsiString(usFHiValue[i]);
            txtLo[i]->Text = AnsiString(usFLowValue[i]);
        }

    }        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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