消费机 水控机 售饭机 电梯门禁 门禁机
快速寻找产品(请输入产品型号或名称的关键词):
首页> 技术文档

技术文档

Delphi 控件数组化

发布者:广州荣士电子有限公司         发布时间: 2026-7-11 

procedure TForm2.Button2Click(Sender: TObject);

var
  i,j,p:Integer;
  pedit:TEdit;
  pcheckbox:TCheckBox;
  pcombobox:TComboBox;
  mykey:array[0..5] of byte;

begin
  SetLength(Form1.ResponseBuff, 134);
  Form1.ResponseBuff[0]:=$4B;   //命令字:设置读写器读卡扇区及卡片认证密钥
  Form1.ResponseBuff[1]:=$00;   //机号低
  Form1.ResponseBuff[2]:=$00;   //机号高,0000表示任意机号

  Form1.ResponseBuff[3]:=0;
  i:=0;
  j:=4;

  for p := 1 to 16 do
  begin
    pedit := TEdit(FindComponent('Edit' + IntToStr(p)));
    pcheckbox:= TCheckBox(FindComponent('CheckBox' + IntToStr(p)));
    pcombobox:= TComboBox(FindComponent('ComboBox' + IntToStr(p)));

    if pcheckbox.Checked = true then
    begin
       if (Length(pedit.Text) = 12) and (Form1.checkhexstr(pedit.Text ,6,mykey)=true) then    //检测密钥是否合法
       begin
            Form1.ResponseBuff[3]:=Form1.ResponseBuff[3]+1;
            Form1.ResponseBuff[j]:= p-1;
            if pcombobox.ItemIndex>0  then Form1.ResponseBuff[j]:=Form1.ResponseBuff[j] or 128;  ////如果是认证B密码
            for i:=0 to 5 do
            begin
                j:=j+1;
                Form1.ResponseBuff[j]:=mykey[i];
            end;
            j:=j+1;
       end
       else
       begin
            Application.MessageBox(PAnsiChar(AnsiString('密钥输入错误,请输入12位16进制密钥!')), '提示', MB_OK+MB_ICONINFORMATION);
            pedit.SetFocus;
            pedit.SelStart := Length(pedit.Text);
            Exit;
       end;
    end;
  end;

  p:=Form1.ResponseBuff[3];
  Form1.ResponseBuff[4+p*7]:=$55;
  Form1.ResponseBuff[5+p*7]:=$aa;
  Form1.ResponseBuff[6+p*7]:=$66;
  Form1.ResponseBuff[7+p*7]:=$99;
  SetLength(Form1.ResponseBuff, 8+p*7);   //减去多余的发送缓冲数据

  Edit17.Text :='';
  Form1.ButtonSend(5);   //发送数据已准备好,发送指令

end;
 
已是第一篇 下一篇:如何从分享链接中获取音乐ID并写入NFC标签
     
Guangzhou Rong Shi Electronics Co., Ltd., China 广州荣士电子有限公司 备案/许可证编号:粤ICP备11063836号
TEL  020-22307058    020-82301718
消费机
隐私政策

消费机 水控机 售饭机 电梯门禁 门禁机

网站地图 xml