patternform.cpp
来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 145 行
CPP
145 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PatternForm.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmPattern *frmPattern;
extern USHORT usPEnable, usPValue;
//---------------------------------------------------------------------------
__fastcall TfrmPattern::TfrmPattern(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmPattern::chkPatternBit7Click(TObject *Sender)
{
TCheckBox *chk = (TCheckBox* )(Sender);
if(chk->Checked){
if(chk == chkPatternBit0){
optPatternBitHi0->Enabled = True;
optPatternBitLo0->Enabled = True;
}else if(chk == chkPatternBit1){
optPatternBitHi1->Enabled = True;
optPatternBitLo1->Enabled = True;
}else if(chk == chkPatternBit2){
optPatternBitHi2->Enabled = True;
optPatternBitLo2->Enabled = True;
}else if(chk == chkPatternBit3){
optPatternBitHi3->Enabled = True;
optPatternBitLo3->Enabled = True;
}else if(chk == chkPatternBit4){
optPatternBitHi4->Enabled = True;
optPatternBitLo4->Enabled = True;
}else if(chk == chkPatternBit5){
optPatternBitHi5->Enabled = True;
optPatternBitLo5->Enabled = True;
}else if(chk == chkPatternBit6){
optPatternBitHi6->Enabled = True;
optPatternBitLo6->Enabled = True;
}else{
optPatternBitHi7->Enabled = True;
optPatternBitLo7->Enabled = True;
}
}else{
if(chk == chkPatternBit0){
optPatternBitHi0->Enabled = False;
optPatternBitLo0->Enabled = False;
}else if(chk == chkPatternBit1){
optPatternBitHi1->Enabled = False;
optPatternBitLo1->Enabled = False;
}else if(chk == chkPatternBit2){
optPatternBitHi2->Enabled = False;
optPatternBitLo2->Enabled = False;
}else if(chk == chkPatternBit3){
optPatternBitHi3->Enabled = False;
optPatternBitLo3->Enabled = False;
}else if(chk == chkPatternBit4){
optPatternBitHi4->Enabled = False;
optPatternBitLo4->Enabled = False;
}else if(chk == chkPatternBit5){
optPatternBitHi5->Enabled = False;
optPatternBitLo5->Enabled = False;
}else if(chk == chkPatternBit6){
optPatternBitHi6->Enabled = False;
optPatternBitLo6->Enabled = False;
}else{
optPatternBitHi7->Enabled = False;
optPatternBitLo7->Enabled = False;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPattern::cmdOkClick(TObject *Sender)
{
TCheckBox* chbox[8] = {chkPatternBit0,chkPatternBit1,chkPatternBit2,chkPatternBit3,chkPatternBit4,chkPatternBit5,
chkPatternBit6,chkPatternBit7};
TRadioButton* rdbHi[8] = {optPatternBitHi0,optPatternBitHi1,optPatternBitHi2,
optPatternBitHi3,optPatternBitHi4,optPatternBitHi5,
optPatternBitHi6,optPatternBitHi7};
TRadioButton* rdbLo[8] = {optPatternBitLo0,optPatternBitLo1,optPatternBitLo2,
optPatternBitLo3,optPatternBitLo4,optPatternBitLo5,
optPatternBitLo6,optPatternBitLo7};
usPEnable = 0, usPValue = 0;
for(int i=0; i<8; i++){
if(chbox[i]->Checked){
usPEnable |= (0x01<<i);
if(rdbHi[i]->Checked){
usPValue |= (0x01<<i);
}else if(rdbLo[i]->Checked){
usPValue &= ~(0x01<<i);
}
}else{
usPEnable &= ~(0x01<<i);
}
}
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPattern::cmdCancelClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPattern::FormShow(TObject *Sender)
{
TCheckBox* chbox[8] = {chkPatternBit0,chkPatternBit1,chkPatternBit2,chkPatternBit3,chkPatternBit4,chkPatternBit5,
chkPatternBit6,chkPatternBit7};
TRadioButton* rdbHi[8] = {optPatternBitHi0,optPatternBitHi1,optPatternBitHi2,
optPatternBitHi3,optPatternBitHi4,optPatternBitHi5,
optPatternBitHi6,optPatternBitHi7};
TRadioButton* rdbLo[8] = {optPatternBitLo0,optPatternBitLo1,optPatternBitLo2,
optPatternBitLo3,optPatternBitLo4,optPatternBitLo5,
optPatternBitLo6,optPatternBitLo7};
for(int i=0; i<8; i++){
if(usPEnable&(USHORT)pow(2,i)){
chbox[i]->Checked = True;
if(usPValue & (USHORT)pow(2,i)){
rdbHi[i]->Checked = True;
}else{
rdbLo[i]->Checked = True;
}
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?