mainform.pas
上传用户:jitai139
上传日期:2013-04-11
资源大小:1244k
文件大小:149k
开发平台:

Delphi

  1. unit mainform;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls, ExtCtrls, ComCtrls,math;
  6. type
  7.   TForm1 = class(TForm)
  8.     Panel1: TPanel;
  9.     GroupBox1: TGroupBox;
  10.     Edit1: TEdit;
  11.     GroupBox2: TGroupBox;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     Label3: TLabel;
  15.     Label4: TLabel;
  16.     Label5: TLabel;
  17.     Label6: TLabel;
  18.     Edit2: TEdit;
  19.     Edit3: TEdit;
  20.     Edit4: TEdit;
  21.     Edit5: TEdit;
  22.     Edit6: TEdit;
  23.     Edit7: TEdit;
  24.     Edit8: TEdit;
  25.     Edit9: TEdit;
  26.     Edit10: TEdit;
  27.     Edit11: TEdit;
  28.     Edit12: TEdit;
  29.     Edit13: TEdit;
  30.     Edit14: TEdit;
  31.     Edit15: TEdit;
  32.     Edit16: TEdit;
  33.     Edit17: TEdit;
  34.     Edit18: TEdit;
  35.     Edit19: TEdit;
  36.     Button1: TButton;
  37.     Button2: TButton;
  38.     Button3: TButton;
  39.     Button4: TButton;
  40.     Button5: TButton;
  41.     Button6: TButton;
  42.     Button7: TButton;
  43.     Button8: TButton;
  44.     Button9: TButton;
  45.     Button10: TButton;
  46.     Button11: TButton;
  47.     Button12: TButton;
  48.     Button13: TButton;
  49.     Button14: TButton;
  50.     Button15: TButton;
  51.     Button16: TButton;
  52.     Button17: TButton;
  53.     Button18: TButton;
  54.     Edit20: TEdit;
  55.     Edit21: TEdit;
  56.     Edit22: TEdit;
  57.     Edit23: TEdit;
  58.     Edit24: TEdit;
  59.     Edit25: TEdit;
  60.     Button19: TButton;
  61.     Button20: TButton;
  62.     Button21: TButton;
  63.     GroupBox3: TGroupBox;
  64.     ComboBox1: TComboBox;
  65.     Button22: TButton;
  66.     GroupBox4: TGroupBox;
  67.     Edit26: TEdit;
  68.     Label7: TLabel;
  69.     Button24: TButton;
  70.     GroupBox5: TGroupBox;
  71.     ComboBox2: TComboBox;
  72.     Edit27: TEdit;
  73.     Edit28: TEdit;
  74.     Button25: TButton;
  75.     MSComm1: TMSComm;
  76.     StatusBar1: TStatusBar;
  77.     Timer1: TTimer;
  78.     Button26: TButton;
  79.     OpenDialog1: TOpenDialog;
  80.     SaveDialog1: TSaveDialog;
  81.     Button27: TButton;
  82.     Timer2: TTimer;
  83.     Timer3: TTimer;
  84.     Timer4: TTimer;
  85.     Timer5: TTimer;
  86.     Timer6: TTimer;
  87.     Timer7: TTimer;
  88.     Timer8: TTimer;
  89.     Timer9: TTimer;
  90.     Timer10: TTimer;
  91.     Timer11: TTimer;
  92.     Timer12: TTimer;
  93.     Timer13: TTimer;
  94.     Timer14: TTimer;
  95.     Button28: TButton;
  96.     SaveDialog2: TSaveDialog;
  97.     Shape1: TShape;
  98.     Timer15: TTimer;
  99.     Timer16: TTimer;
  100.     Label8: TLabel;
  101.     Label9: TLabel;
  102.     Label10: TLabel;
  103.     Memo1: TMemo;
  104.     CheckBox1: TCheckBox;
  105.     CheckBox2: TCheckBox;
  106.     CheckBox3: TCheckBox;
  107.     CheckBox4: TCheckBox;
  108.     CheckBox5: TCheckBox;
  109.     CheckBox6: TCheckBox;
  110.     Label12: TLabel;
  111.     Edit29: TEdit;
  112.     Label13: TLabel;
  113.     Label14: TLabel;
  114.     Edit30: TEdit;
  115.     Label15: TLabel;
  116.     Edit31: TEdit;
  117.     Label16: TLabel;
  118.     ComboBox3: TComboBox;
  119.     ComboBox4: TComboBox;
  120.     ComboBox5: TComboBox;
  121.     ComboBox6: TComboBox;
  122.     ComboBox7: TComboBox;
  123.     ComboBox8: TComboBox;
  124.     Label17: TLabel;
  125.     Label18: TLabel;
  126.     Label19: TLabel;
  127.     Label20: TLabel;
  128.     Label21: TLabel;
  129.     Label22: TLabel;
  130.     Button23: TButton;
  131.     Label11: TLabel;
  132.     Button29: TButton;
  133.     procedure Button22Click(Sender: TObject);
  134.     procedure Button3Click(Sender: TObject);
  135.     procedure Button6Click(Sender: TObject);
  136.     procedure Button9Click(Sender: TObject);
  137.     procedure Button12Click(Sender: TObject);
  138.     procedure Button15Click(Sender: TObject);
  139.     procedure Button18Click(Sender: TObject);
  140.     procedure Button2Click(Sender: TObject);
  141.     procedure Timer1Timer(Sender: TObject);
  142.     procedure FormCreate(Sender: TObject);
  143.     procedure Button26Click(Sender: TObject);
  144.     procedure Button27Click(Sender: TObject);
  145.     procedure Button5Click(Sender: TObject);
  146.     procedure Button8Click(Sender: TObject);
  147.     procedure Button11Click(Sender: TObject);
  148.     procedure Button14Click(Sender: TObject);
  149.     procedure Button17Click(Sender: TObject);
  150.     procedure Timer2Timer(Sender: TObject);
  151.     procedure Timer3Timer(Sender: TObject);
  152.     procedure Timer4Timer(Sender: TObject);
  153.     procedure Timer5Timer(Sender: TObject);
  154.     procedure Timer6Timer(Sender: TObject);
  155.     procedure Button21Click(Sender: TObject);
  156.     procedure Button1Click(Sender: TObject);
  157.     procedure Timer7Timer(Sender: TObject);
  158.     procedure Button4Click(Sender: TObject);
  159.     procedure Button7Click(Sender: TObject);
  160.     procedure Button10Click(Sender: TObject);
  161.     procedure Button13Click(Sender: TObject);
  162.     procedure Button16Click(Sender: TObject);
  163.     procedure Timer8Timer(Sender: TObject);
  164.     procedure Timer9Timer(Sender: TObject);
  165.     procedure Timer10Timer(Sender: TObject);
  166.     procedure Timer11Timer(Sender: TObject);
  167.     procedure Timer12Timer(Sender: TObject);
  168.     procedure Button24Click(Sender: TObject);
  169.     procedure Timer13Timer(Sender: TObject);
  170.     procedure Button25Click(Sender: TObject);
  171.     procedure Timer14Timer(Sender: TObject);
  172.     procedure Button28Click(Sender: TObject);
  173.     procedure Button19Click(Sender: TObject);
  174.     procedure Timer15Timer(Sender: TObject);
  175.     procedure Button20Click(Sender: TObject);
  176.     procedure Timer16Timer(Sender: TObject);
  177.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  178.     procedure ComboBox1Change(Sender: TObject);
  179.     procedure ComboBox2Change(Sender: TObject);
  180.     procedure Button23Click(Sender: TObject);
  181.    // procedure Edit1Enter(Sender: TObject);
  182.    
  183.    // function setvar(tag:boolean;btn:tbutton):integer;
  184.   private
  185.     { Private declarations }
  186.     function   TsInputVal(staStr:string):boolean;
  187.   public
  188.     { Public declarations }
  189.    timesum,tag,success,p,tagc,pc:integer;
  190.    flag:boolean;
  191.    zuhao:integer;
  192.    tindexnum:integer;
  193.   end;
  194. var
  195.   Form1: TForm1;
  196. implementation
  197.   //uses sysutils;
  198. {$R *.dfm}
  199. {function setvar(tag:boolean;btn:tbutton):integer;
  200. var
  201. i:integer;
  202.   begin
  203.   i:=-1;
  204.   while tag<>true do begin
  205.     if (edit2.)or()or()or()or()or()
  206.                        btn.Click;
  207.                      end;
  208.   i:=1  ;
  209.    tag:=false;
  210.    result:= i;
  211.  end;  }
  212.  //function  senddata(cid:integer) :boolean;
  213. //hao add
  214. function TForm1.TsInputVal(staStr:string):boolean;
  215.   var
  216.     flag1,flag2:boolean ;
  217.     f:real;
  218.   begin
  219.     f:=strToFloat(staStr);
  220.     if f>=0.000 then
  221.        flag1:=true
  222.     else
  223.        flag1:=false;
  224.     if  f<=9.999 then
  225.         flag2:=true
  226.     else
  227.        flag2:=false;
  228.     if flag1 and flag2 then
  229.        begin
  230.         result:=true;
  231.         exit;
  232.        end
  233.      else
  234.        begin
  235.          showmessage('输入或所得的设定值非法!!--范围在:0.000~9.999 之间。');
  236.          result:=false;
  237.        end;
  238. end;
  239.  PROCEDURE TIMEDELAY(DT:DWORD);                  //延时程序 timedelay(sencond)
  240.   VAR
  241.     TT:DWORD;
  242.   begin
  243.     //取得现在的TICK值
  244.     TT:=GetTickCount();
  245.     //计算TICK差值是否超过设置之
  246.   while GetTickCount()-TT<DT do
  247.    APPLICATION.ProcessMessages;//释放控制权
  248.   end;
  249.   function hex(c:char):integer;                  //16进制转换
  250. var
  251. x:integer;
  252. begin
  253.     if c='' then
  254.       x:=0
  255.       else if (ord(c)>=ord('0'))and(ord(c)<=ord('9')) then
  256.       x:=ord(c)-ord('0')
  257.       else if (ord(c)>=ord('a'))and(ord(c)<=ord('f')) then
  258.       x:=ord(c)-ord('a')+10
  259.       else if (ord(c)>=ord('A'))and(ord(c)<=ord('F')) then
  260.       x:=ord(c)-ord('A')+10
  261.       else
  262.       x:=-1;
  263.      result:=x;
  264. end;
  265. function hextoint(s:string):integer ;                  //16进制toINT
  266. var
  267.   tmpstr1,tmpstr2:integer;
  268. begin
  269.  if length(s)=1 then
  270.   begin
  271.      result:=hex(s[1]);
  272.   end
  273.   else if length(s)=2 then
  274.   begin
  275.   tmpstr1:=hex(s[1]) ;
  276.   tmpstr2:=hex(s[2]);
  277.     if(tmpstr1=-1)and(tmpstr2=-1) then
  278.     result:=-1
  279.     else
  280.     result:=tmpstr1*16+tmpstr2;
  281.    end
  282.    else
  283.     result:=-1;
  284. end;
  285. procedure TForm1.Button22Click(Sender: TObject);       //open the serial port
  286. begin
  287.    if  not mscomm1.PortOpen then
  288.     begin
  289.           mscomm1.CommPort:=combobox1.ItemIndex+1;
  290.          tindexnum:= combobox1.ItemIndex;
  291.       mscomm1.Settings:='2400,n,8,1';
  292.            mscomm1.PortOpen:=true;
  293.            statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已打开';
  294.            shape1.Brush.Color:=clgreen;
  295.            button22.Caption:='断开';
  296.     end else
  297.     begin
  298.        mscomm1.PortOpen:=false;
  299.            shape1.Brush.Color:=clred;
  300.             tindexnum:= combobox1.ItemIndex;
  301.            statusbar1.Panels[0].Text:='串口com'+inttostr(combobox1.ItemIndex+1)+'已关闭';
  302.            button22.Caption:='连接';
  303.              edit4.Text:='';
  304.    edit7.Text:='';
  305.    edit10.Text:='';
  306.    edit13.Text:='';
  307.    edit16.Text:='';
  308.    edit19.Text:='';
  309.    combobox2.ItemIndex:=0;
  310.    label8.Visible:=false;
  311.  label9.Visible:=false;
  312.  label10.Visible:=false;
  313. label11.Visible:=false;
  314.  label12.Visible:=false;
  315.  label13.Visible:=false;
  316.  label14.Visible:=false;
  317.  label15.Visible:=false;
  318.  label16.Visible:=false;
  319.  edit27.Visible:=false;
  320.  edit28.Visible:=false;
  321.  edit29.Visible:=false;
  322.  edit30.Visible:=false;
  323.   edit31.Visible:=false;
  324.     end;
  325.     // mscomm1.CommPort:=combobox1.ItemIndex+1;
  326.       //mscomm1.Settings:='2400,n,8,1';
  327.      // mscomm1.PortOpen:=true;
  328.       //statusbar1.Panels[0].Text:='serial was open';
  329.       //shape1.Brush.Color:=clgreen;
  330.       //edit3.Text:='';
  331.   edit4.Text:='';
  332.  // edit6.Text:='';
  333.    edit7.Text:='';
  334.   // edit9.Text:='';
  335.    edit10.Text:='';
  336.   // edit12.Text:='';
  337.    edit13.Text:='';
  338.    //edit15.Text:='';
  339.    edit16.Text:='';
  340.   // edit18.Text:='';
  341.    edit19.Text:='';
  342. end;
  343. procedure TForm1.Button3Click(Sender: TObject);
  344. var
  345.   a,b:real;
  346.   c: real;
  347.  m,n:variant;
  348.  str1:string;
  349.  ll:integer;
  350. begin
  351. c:=0.00;
  352.   if (edit3.Text<>'') and (edit4.Text<>'') then
  353.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  354.  begin
  355.  showmessage('数值超出合理范围(-45.00~+25.00)'); /////////////////////////////////
  356.  edit3.Text:='';
  357.   end else begin }
  358.        str1:=label17.Caption;
  359.   if str1='dBm' then  begin
  360.       a:=strtofloat(edit4.Text);
  361.       n:=a;
  362.       a:=power(10,n/10.0);              //dbm to mw
  363.       a:=a*1000.0;                       //mw to uw
  364.       b:=strtofloat(edit3.Text);
  365.       ll:=combobox3.ItemIndex;
  366.       case ll of
  367.         0:begin if (b<=-70) or (b>=10) then
  368.         begin
  369.         showmessage('输入的数值超出范围!') ;
  370.          edit3.Text:='';
  371.          end
  372.         else begin
  373.          b:=power(10,b/10.0);
  374.           b:=b*1000.0;
  375.           c:= b/ a;
  376.            edit2.Text:=formatfloat('0.000',c);
  377.           end;
  378.           end;
  379.          1:begin if (b>10) or (b<1/10000000) then begin
  380.           showmessage('输入数值超出范围!');
  381.             edit3.Text:='';
  382.             end
  383.          else begin b:= b*1000.0;
  384.          c:= b/ a;
  385.   edit2.Text:=formatfloat('0.000',c);
  386.   end;
  387.    end;
  388.          2:begin if (b>1000)or (b<1/10000) then begin
  389.           showmessage('输入数值超出范围!');
  390.           edit3.Text:='';
  391.           end
  392.          else begin  b:= b;
  393.          c:= b/ a;
  394.   edit2.Text:=formatfloat('0.000',c);
  395.   end;
  396.   end;
  397.          3:begin if (b>1000000)or (b<1/10) then begin
  398.           showmessage('输入数值超出范围!');
  399.              edit3.Text:='';
  400.           end
  401.          else begin  b:= b/1000.0;
  402.          c:= b/ a;
  403.   edit2.Text:=formatfloat('0.000',c);;
  404.          end;
  405.          end;
  406.               // c:= m/ n;
  407.   //edit2.Text:=formatfloat('0.000',c);
  408.   end;
  409.   end;
  410.   if str1='uw' then begin
  411.       a:=strtofloat(edit4.Text);
  412.       n:=a;
  413.      // m:=m;
  414.       b:=strtofloat(edit3.Text);
  415.      ll:=combobox3.ItemIndex;
  416.       case ll of
  417.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  418.          1:m:= b*1000.0;
  419.          2:m:= b;
  420.          3:m:= b/1000.0; }
  421.       0:begin if (b<=-70) or (b>=10) then
  422.         begin
  423.         showmessage('输入的数值超出范围!') ;
  424.          edit3.Text:='';
  425.          end
  426.         else begin
  427.          b:=power(10,b/10.0);
  428.           b:=b*1000.0;
  429.           c:= b/a;
  430.            edit2.Text:=formatfloat('0.000',c);
  431.           end;
  432.           end;
  433.          1:begin if (b>10) or (b<1/10000000) then begin
  434.           showmessage('输入数值超出范围!');
  435.             edit3.Text:='';
  436.             end
  437.          else begin b:= b*1000.0;
  438.          c:= b/ a;
  439.   edit2.Text:=formatfloat('0.000',c);
  440.   end;
  441.    end;
  442.          2:begin if (b>1000)or (b<1/10000) then begin
  443.           showmessage('输入数值超出范围!');
  444.           edit3.Text:='';
  445.           end
  446.          else begin  b:= b;
  447.          c:= b/ a;
  448.   edit2.Text:=formatfloat('0.000',c);
  449.   end;
  450.   end;
  451.          3:begin if (b>1000000)or (b<1/10) then begin
  452.           showmessage('输入数值超出范围!');
  453.              edit3.Text:='';
  454.           end
  455.          else begin  b:= b/1000.0;
  456.          c:= b/a;
  457.   edit2.Text:=formatfloat('0.000',c);;
  458.          end;
  459.          end;
  460.     //  c:= m/ n;
  461.     end;
  462.  // edit2.Text:=formatfloat('0.000',c);
  463.  end;
  464.       if str1='nw' then begin
  465.        a:=strtofloat(edit4.Text);
  466.       n:=a;
  467.       a:=a/1000.0;
  468.       b:=strtofloat(edit3.Text);
  469.       ll:=combobox3.ItemIndex;
  470.       case ll of
  471.        { 0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  472.          1:m:= b*1000.0;
  473.          2:m:= b;
  474.          3:m:= b/1000.0;
  475.          end;  }
  476.        0:begin if (b<=-70) or (b>=10) then
  477.         begin
  478.         showmessage('输入的数值超出范围!') ;
  479.          edit3.Text:='';
  480.          end
  481.         else begin
  482.          b:=power(10,b/10.0);
  483.           b:=b*1000.0;
  484.           c:= b/ a;
  485.            edit2.Text:=formatfloat('0.000',c);
  486.           end;
  487.           end;
  488.          1:begin if (b>10) or (b<1/10000000) then begin
  489.           showmessage('输入数值超出范围!');
  490.             edit3.Text:='';
  491.             end
  492.          else begin b:= b*1000.0;
  493.          c:= b/ a;
  494.   edit2.Text:=formatfloat('0.000',c);
  495.   end;
  496.    end;
  497.          2:begin if (b>1000)or (b<1/10000) then begin
  498.           showmessage('输入数值超出范围!');
  499.           edit3.Text:='';
  500.           end
  501.          else begin  b:= b;
  502.          c:= b/ a;
  503.   edit2.Text:=formatfloat('0.000',c);
  504.   end;
  505.   end;
  506.          3:begin if (b>1000000)or (b<1/10) then begin
  507.           showmessage('输入数值超出范围!');
  508.              edit3.Text:='';
  509.           end
  510.          else begin  b:= b/1000.0;
  511.          c:= b/ a;
  512.   edit2.Text:=formatfloat('0.000',c);;
  513.          end;
  514.     //  c:= m/ n;
  515.          end;
  516.   //edit2.Text:=formatfloat('0.000',c);
  517.       end;
  518.       end;
  519.       if str1='mw' then begin
  520.         a:=strtofloat(edit4.Text);
  521.       n:=a;
  522.       a:=a*1000.0;
  523.       b:=strtofloat(edit3.Text);
  524.       ll:=combobox3.ItemIndex;
  525.       case ll of
  526.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  527.          1:m:= b*1000.0;
  528.          2:m:= b;
  529.          3:m:= b/1000.0;  }
  530.    0:begin if (b<=-70) or (b>=10) then
  531.         begin
  532.         showmessage('输入的数值超出范围!') ;
  533.          edit3.Text:='';
  534.          end
  535.         else begin
  536.          b:=power(10,b/10.0);
  537.           b:=b*1000.0;
  538.           c:= b/ a;
  539.            edit2.Text:=formatfloat('0.000',c);
  540.           end;
  541.           end;
  542.          1:begin if (b>10) or (b<1/10000000) then begin
  543.           showmessage('输入数值超出范围!');
  544.             edit3.Text:='';
  545.             end
  546.          else begin b:= b*1000.0;
  547.          c:= b/ a;
  548.   edit2.Text:=formatfloat('0.000',c);
  549.   end;
  550.    end;
  551.          2:begin if (b>1000)or (b<1/10000) then begin
  552.           showmessage('输入数值超出范围!');
  553.           edit3.Text:='';
  554.           end
  555.          else begin  b:= b;
  556.          c:= b/ a;
  557.   edit2.Text:=formatfloat('0.000',c);
  558.   end;
  559.   end;
  560.          3:begin if (b>1000000)or (b<1/10) then begin
  561.           showmessage('输入数值超出范围!');
  562.              edit3.Text:='';
  563.           end
  564.          else begin  b:= b/1000.0;
  565.          c:= b/ a;
  566.   edit2.Text:=formatfloat('0.000',c);;
  567.          end;
  568.          end;
  569.   //edit2.Text:=formatfloat('0.000',c);
  570. end;
  571.  end;
  572.   end
  573.   else
  574.   begin
  575.       showmessage('请先输入正确的值!');
  576.   end;
  577. end;
  578. //end;
  579. //end;
  580. //end;
  581. procedure TForm1.Button9Click(Sender: TObject);
  582. var
  583.   a,b:real;
  584.   c: real;
  585.  m,n:variant;
  586.  str1:string;
  587.  ll:integer;
  588. begin
  589. c:=0.00;
  590.   if (edit9.Text<>'') and (edit10.Text<>'') then
  591.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  592.  begin
  593.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  594.  edit3.Text:='';
  595.   end else begin }
  596.        str1:=label19.Caption;
  597.   if str1='dBm' then  begin
  598.       a:=strtofloat(edit10.Text);
  599.       n:=a;
  600.       a:=power(10,a/10.0);              //dbm to mw
  601.       a:=a*1000.0;                       //mw to uw
  602.       b:=strtofloat(edit9.Text);
  603.       ll:=combobox5.ItemIndex;
  604.       case ll of
  605.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  606.          1:m:= b*1000.0;
  607.          2:m:= b;
  608.          3:m:= b/1000.0
  609.          end;  }
  610.          0:begin if (b<=-70) or (b>=10) then
  611.         begin
  612.         showmessage('输入的数值超出范围!') ;
  613.          edit9.Text:='';
  614.          end
  615.         else begin
  616.          b:=power(10,b/10.0);
  617.           b:=b*1000.0;
  618.           c:= b/a;
  619.            edit8.Text:=formatfloat('0.000',c);
  620.           end;
  621.           end;
  622.          1:begin if (b>10) or (b<1/10000000) then begin
  623.           showmessage('输入数值超出范围!');
  624.             edit9.Text:='';
  625.             end
  626.          else begin b:= b*1000.0;
  627.          c:= b/ a;
  628.   edit8.Text:=formatfloat('0.000',c);
  629.   end;
  630.    end;
  631.          2:begin if (b>1000)or (b<1/10000) then begin
  632.           showmessage('输入数值超出范围!');
  633.           edit9.Text:='';
  634.           end
  635.          else begin  b:= b;
  636.          c:= b/ a;
  637.   edit8.Text:=formatfloat('0.000',c);
  638.   end;
  639.   end;
  640.          3:begin if (b>1000000)or (b<1/10) then begin
  641.           showmessage('输入数值超出范围!');
  642.              edit9.Text:='';
  643.           end
  644.          else begin  b:= b/1000.0;
  645.          c:= b/ a;
  646.   edit8.Text:=formatfloat('0.000',c);;
  647.          end;
  648.          end;
  649.      // c:= m/ n;
  650.        end;
  651.   //edit8.Text:=formatfloat('0.000',c);
  652.   end;
  653.   if str1='uw' then begin
  654.       a:=strtofloat(edit10.Text);
  655.       n:=a;
  656.      // m:=m;
  657.       b:=strtofloat(edit9.Text);
  658.      ll:=combobox5.ItemIndex;
  659.       case ll of
  660.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  661.          1:m:= b*1000.0;
  662.          2:m:= b;
  663.          3:m:= b/1000.0   }
  664.           0:begin if (b<=-70) or (b>=10) then
  665.         begin
  666.         showmessage('输入的数值超出范围!') ;
  667.          edit9.Text:='';
  668.          end
  669.         else begin
  670.          b:=power(10,b/10.0);
  671.           b:=b*1000.0;
  672.           c:= b/ a;
  673.            edit8.Text:=formatfloat('0.000',c);
  674.           end;
  675.           end;
  676.          1:begin if (b>10) or (b<1/10000000) then begin
  677.           showmessage('输入数值超出范围!');
  678.             edit9.Text:='';
  679.             end
  680.          else begin b:= b*1000.0;
  681.          c:= b/ a;
  682.   edit8.Text:=formatfloat('0.000',c);
  683.   end;
  684.    end;
  685.          2:begin if (b>1000)or (b<1/10000) then begin
  686.           showmessage('输入数值超出范围!');
  687.           edit9.Text:='';
  688.           end
  689.          else begin  b:= b;
  690.          c:=b/a;
  691.   edit8.Text:=formatfloat('0.000',c);
  692.   end;
  693.   end;
  694.          3:begin if (b>1000000)or (b<1/10) then begin
  695.           showmessage('输入数值超出范围!');
  696.              edit9.Text:='';
  697.           end
  698.          else begin  b:= b/1000.0;
  699.          c:= b/ a;
  700.   edit8.Text:=formatfloat('0.000',c);;
  701.          end;
  702.          end;
  703.          end;
  704.       //c:= m/ n;
  705.  // edit8.Text:=formatfloat('0.000',c);
  706.       end;
  707.       if str1='nw' then begin
  708.        a:=strtofloat(edit10.Text);
  709.       n:=a;
  710.       a:=a/1000.0;
  711.       b:=strtofloat(edit9.Text);
  712.       ll:=combobox5.ItemIndex;
  713.       case ll of
  714.         {0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  715.          1:m:= b*1000.0;
  716.          2:m:= b;
  717.          3:m:= b/1000.0   }
  718.           0:begin if (b<=-70) or (b>=10) then
  719.         begin
  720.         showmessage('输入的数值超出范围!') ;
  721.          edit9.Text:='';
  722.          end
  723.         else begin
  724.          b:=power(10,b/10.0);
  725.           b:=b*1000.0;
  726.           c:= b/ a;
  727.            edit8.Text:=formatfloat('0.000',c);
  728.           end;
  729.           end;
  730.          1:begin if (b>10) or (b<1/10000000) then begin
  731.           showmessage('输入数值超出范围!');
  732.             edit9.Text:='';
  733.             end
  734.          else begin b:= b*1000.0;
  735.          c:= b/a;
  736.   edit8.Text:=formatfloat('0.000',c);
  737.   end;
  738.    end;
  739.          2:begin if (b>1000)or (b<1/10000) then begin
  740.           showmessage('输入数值超出范围!');
  741.           edit9.Text:='';
  742.           end
  743.          else begin  b:= b;
  744.          c:= b/ a;
  745.   edit8.Text:=formatfloat('0.000',c);
  746.   end;
  747.   end;
  748.          3:begin if (b>1000000)or (b<1/10) then begin
  749.           showmessage('输入数值超出范围!');
  750.              edit9.Text:='';
  751.           end
  752.          else begin  b:= b/1000.0;
  753.          c:= b/ a;
  754.   edit8.Text:=formatfloat('0.000',c);;
  755.          end;
  756.          end;
  757.          end;
  758.      // c:= m/ n;
  759.   //edit8.Text:=formatfloat('0.000',c);
  760.       end;
  761.       if str1='mw' then begin
  762.         a:=strtofloat(edit10.Text);
  763.       n:=a;
  764.       a:=a*1000.0;
  765.       b:=strtofloat(edit9.Text);
  766.       ll:=combobox5.ItemIndex;
  767.       case ll of
  768.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  769.          1:m:= b*1000.0;
  770.          2:m:= b;
  771.          3:m:= b/1000.0   }
  772.  0:begin if (b<=-70) or (b>=10) then
  773.         begin
  774.         showmessage('输入的数值超出范围!') ;
  775.          edit9.Text:='';
  776.          end
  777.         else begin
  778.          b:=power(10,b/10.0);
  779.           b:=b*1000.0;
  780.           c:= b/a;
  781.            edit8.Text:=formatfloat('0.000',c);
  782.           end;
  783.           end;
  784.          1:begin if (b>10) or (b<1/10000000) then begin
  785.           showmessage('输入数值超出范围!');
  786.             edit9.Text:='';
  787.             end
  788.          else begin b:= b*1000.0;
  789.          c:= b/ a;
  790.   edit8.Text:=formatfloat('0.000',c);
  791.   end;
  792.    end;
  793.          2:begin if (b>1000)or (b<1/10000) then begin
  794.           showmessage('输入数值超出范围!');
  795.           edit9.Text:='';
  796.           end
  797.          else begin  b:= b;
  798.          c:= b/ a;
  799.   edit8.Text:=formatfloat('0.000',c);
  800.   end;
  801.   end;
  802.          3:begin if (b>1000000)or (b<1/10) then begin
  803.           showmessage('输入数值超出范围!');
  804.              edit9.Text:='';
  805.           end
  806.          else begin  b:= b/1000.0;
  807.          c:= b/a;
  808.   edit8.Text:=formatfloat('0.000',c);;
  809.          end;
  810.          end;
  811.          end;
  812.  // edit8.Text:=formatfloat('0.000',c);
  813. end;
  814.  // end;
  815.   end
  816.   else
  817.   begin
  818.       showmessage('请先输入正确的值!');
  819.   end;
  820. end;
  821.  // end;
  822.  // end;
  823. procedure TForm1.Button6Click(Sender: TObject);
  824. var
  825.   a,b:real;
  826.   c: real;
  827.  m,n:variant;
  828.  str1:string;
  829.  ll:integer;
  830. begin
  831.   c:=0.00;
  832.   if (edit6.Text<>'') and (edit7.Text<>'') then
  833.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  834.  begin
  835.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  836.  edit3.Text:='';
  837.   end else begin }
  838.        str1:=label18.Caption;
  839.   if str1='dBm' then  begin
  840.       a:=strtofloat(edit7.Text);
  841.       n:=a;
  842.       a:=power(10,a/10.0);              //dbm to mw
  843.       a:=a*1000.0;                       //mw to uw
  844.       b:=strtofloat(edit6.Text);
  845.       ll:=combobox4.ItemIndex;
  846.       case ll of
  847.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  848.          1:m:= b*1000.0;
  849.          2:m:= b;
  850.          3:m:= b/1000.0
  851.          end; }
  852.            0:begin if (b<=-70) or (b>=10) then
  853.         begin
  854.         showmessage('输入的数值超出范围!') ;
  855.          edit6.Text:='';
  856.          end
  857.         else begin
  858.          b:=power(10,b/10.0);
  859.           b:=b*1000.0;
  860.           c:= b/ a;
  861.            edit5.Text:=formatfloat('0.000',c);
  862.           end;
  863.           end;
  864.          1:begin if (b>10) or (b<1/10000000) then begin
  865.           showmessage('输入数值超出范围!');
  866.             edit6.Text:='';
  867.             end
  868.          else begin b:= b*1000.0;
  869.          c:= b/ a;
  870.   edit5.Text:=formatfloat('0.000',c);
  871.   end;
  872.    end;
  873.          2:begin if (b>1000)or (b<1/10000) then begin
  874.           showmessage('输入数值超出范围!');
  875.           edit6.Text:='';
  876.           end
  877.          else begin  b:= b;
  878.          c:= b/ a;
  879.   edit5.Text:=formatfloat('0.000',c);
  880.   end;
  881.   end;
  882.          3:begin if (b>1000000)or (b<1/10) then begin
  883.           showmessage('输入数值超出范围!');
  884.              edit6.Text:='';
  885.           end
  886.          else begin  b:= b/1000.0;
  887.          c:= b/ a;
  888.   edit5.Text:=formatfloat('0.000',c);;
  889.          end;
  890.          end;
  891.      // c:= m/ n;
  892.   //edit5.Text:=formatfloat('0.000',c);
  893.   end;
  894.   end;
  895.   if str1='uw' then begin
  896.       a:=strtofloat(edit7.Text);
  897.       n:=a;
  898.      // m:=m;
  899.       b:=strtofloat(edit6.Text);
  900.      ll:=combobox4.ItemIndex;
  901.       case ll of
  902.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  903.          1:m:= b*1000.0;
  904.          2:m:= b;
  905.          3:m:= b/1000.0
  906.          end;
  907.       c:= m/ n;
  908.   edit5.Text:=formatfloat('0.000',c);}
  909.    0:begin if (b<=-70) or (b>=10) then
  910.         begin
  911.         showmessage('输入的数值超出范围!') ;
  912.          edit6.Text:='';
  913.          end
  914.         else begin
  915.          b:=power(10,b/10.0);
  916.           b:=b*1000.0;
  917.           c:= b/a;
  918.            edit5.Text:=formatfloat('0.000',c);
  919.           end;
  920.           end;
  921.          1:begin if (b>10) or (b<1/10000000) then begin
  922.           showmessage('输入数值超出范围!');
  923.             edit6.Text:='';
  924.             end
  925.          else begin b:= b*1000.0;
  926.          c:= b/a;
  927.   edit5.Text:=formatfloat('0.000',c);
  928.   end;
  929.    end;
  930.          2:begin if (b>1000)or (b<1/10000) then begin
  931.           showmessage('输入数值超出范围!');
  932.           edit6.Text:='';
  933.           end
  934.          else begin  b:= b;
  935.          c:= b/ a;
  936.   edit5.Text:=formatfloat('0.000',c);
  937.   end;
  938.   end;
  939.          3:begin if (b>1000000)or (b<1/10) then begin
  940.           showmessage('输入数值超出范围!');
  941.              edit6.Text:='';
  942.           end
  943.          else begin  b:= b/1000.0;
  944.          c:= b/ a;
  945.   edit5.Text:=formatfloat('0.000',c);;
  946.          end;
  947.          end;
  948.       end;
  949.       end;
  950.       if str1='nw' then begin
  951.        a:=strtofloat(edit7.Text);
  952.       n:=a;
  953.       a:=a/1000.0;
  954.       b:=strtofloat(edit6.Text);
  955.       ll:=combobox4.ItemIndex;
  956.       case ll of
  957.       {  0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  958.          1:m:= b*1000.0;
  959.          2:m:= b;
  960.          3:m:= b/1000.0
  961.          end;
  962.       c:= m/ n;
  963.   edit5.Text:=formatfloat('0.000',c);  }
  964.    0:begin if (b<=-70) or (b>=10) then
  965.         begin
  966.         showmessage('输入的数值超出范围!') ;
  967.          edit6.Text:='';
  968.          end
  969.         else begin
  970.          b:=power(10,b/10.0);
  971.           b:=b*1000.0;
  972.           c:= b/ a;
  973.            edit5.Text:=formatfloat('0.000',c);
  974.           end;
  975.           end;
  976.          1:begin if (b>10) or (b<1/10000000) then begin
  977.           showmessage('输入数值超出范围!');
  978.             edit6.Text:='';
  979.             end
  980.          else begin b:= b*1000.0;
  981.          c:= b/a ;
  982.   edit5.Text:=formatfloat('0.000',c);
  983.   end;
  984.    end;
  985.          2:begin if (b>1000)or (b<1/10000) then begin
  986.           showmessage('输入数值超出范围!');
  987.           edit6.Text:='';
  988.           end
  989.          else begin  b:= b;
  990.          c:= b/ a;
  991.   edit5.Text:=formatfloat('0.000',c);
  992.   end;
  993.   end;
  994.          3:begin if (b>1000000)or (b<1/10) then begin
  995.           showmessage('输入数值超出范围!');
  996.              edit6.Text:='';
  997.           end
  998.          else begin  b:= b/1000.0;
  999.          c:= b/ a;
  1000.   edit5.Text:=formatfloat('0.000',c);;
  1001.          end;
  1002.          end;
  1003.         end;
  1004.       end;
  1005.       if str1='mw' then begin
  1006.         a:=strtofloat(edit7.Text);
  1007.       n:=a;
  1008.       a:=a*1000.0;
  1009.       b:=strtofloat(edit6.Text);
  1010.       ll:=combobox4.ItemIndex;
  1011.       case ll of
  1012.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1013.          1:m:= b*1000.0;
  1014.          2:m:= b;
  1015.          3:m:= b/1000.0
  1016.          end;
  1017.   edit5.Text:=formatfloat('0.000',c); }
  1018.    0:begin if (b<=-70) or (b>=10) then
  1019.         begin
  1020.         showmessage('输入的数值超出范围!') ;
  1021.          edit6.Text:='';
  1022.          end
  1023.         else begin
  1024.          b:=power(10,b/10.0);
  1025.           b:=b*1000.0;
  1026.           c:= b/ a;
  1027.            edit5.Text:=formatfloat('0.000',c);
  1028.           end;
  1029.           end;
  1030.          1:begin if (b>10) or (b<1/10000000) then begin
  1031.           showmessage('输入数值超出范围!');
  1032.             edit6.Text:='';
  1033.             end
  1034.          else begin b:= b*1000.0;
  1035.          c:= b/ a;
  1036.   edit5.Text:=formatfloat('0.000',c);
  1037.   end;
  1038.    end;
  1039.          2:begin if (b>1000)or (b<1/10000) then begin
  1040.           showmessage('输入数值超出范围!');
  1041.           edit6.Text:='';
  1042.           end
  1043.          else begin  b:= b;
  1044.          c:= b/ a;
  1045.   edit5.Text:=formatfloat('0.000',c);
  1046.   end;
  1047.   end;
  1048.          3:begin if (b>1000000)or (b<1/10) then begin
  1049.           showmessage('输入数值超出范围!');
  1050.              edit6.Text:='';
  1051.           end
  1052.          else begin  b:= b/1000.0;
  1053.          c:= b/a;
  1054.   edit5.Text:=formatfloat('0.000',c);;
  1055.          end;
  1056.          end;
  1057. end;
  1058. end;
  1059.   end
  1060.   else
  1061.   begin
  1062.       showmessage('请先输入正确的值!');
  1063.   end;
  1064. end;
  1065.  procedure TForm1.Button12Click(Sender: TObject);
  1066. var
  1067.   a,b:real;
  1068.   c: real;
  1069.  m,n:variant;
  1070.  str1:string;
  1071.  ll:integer;
  1072. begin
  1073. c:=0.00;
  1074.   if (edit12.Text<>'') and (edit13.Text<>'') then
  1075.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  1076.  begin
  1077.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  1078.  edit3.Text:='';
  1079.   end else begin }
  1080.        str1:=label20.Caption;
  1081.   if str1='dBm' then  begin
  1082.       a:=strtofloat(edit13.Text);
  1083.       n:=a;
  1084.       a:=power(10,a/10.0);              //dbm to mw
  1085.       a:=a*1000.0;                       //mw to uw
  1086.       b:=strtofloat(edit12.Text);
  1087.       ll:=combobox6.ItemIndex;
  1088.       case ll of
  1089.         {0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1090.          1:m:= b*1000.0;
  1091.          2:m:= b;
  1092.          3:m:= b/1000.0 } 0:begin if (b<=-70) or (b>=10) then
  1093.         begin
  1094.         showmessage('输入的数值超出范围!') ;
  1095.          edit12.Text:='';
  1096.          end
  1097.         else begin
  1098.          b:=power(10,b/10.0);
  1099.           b:=b*1000.0;
  1100.           c:= b/ a;
  1101.            edit11.Text:=formatfloat('0.000',c);
  1102.           end;
  1103.           end;
  1104.          1:begin if (b>10) or (b<1/10000000) then begin
  1105.           showmessage('输入数值超出范围!');
  1106.             edit12.Text:='';
  1107.             end
  1108.          else begin b:= b*1000.0;
  1109.          c:= b/ a;
  1110.   edit11.Text:=formatfloat('0.000',c);
  1111.   end;
  1112.    end;
  1113.          2:begin if (b>1000)or (b<1/10000) then begin
  1114.           showmessage('输入数值超出范围!');
  1115.           edit12.Text:='';
  1116.           end
  1117.          else begin  b:= b;
  1118.          c:= b/ a;
  1119.   edit11.Text:=formatfloat('0.000',c);
  1120.   end;
  1121.   end;
  1122.          3:begin if (b>1000000)or (b<1/10) then begin
  1123.           showmessage('输入数值超出范围!');
  1124.              edit12.Text:='';
  1125.           end
  1126.          else begin  b:= b/1000.0;
  1127.          c:= b/ a;
  1128.   edit11.Text:=formatfloat('0.000',c);;
  1129.          end;
  1130.          end;
  1131.          end;
  1132.     //  c:= m/ n;
  1133.  // edit11.Text:=formatfloat('0.000',c);
  1134.   end;
  1135.   if str1='uw' then begin
  1136.       a:=strtofloat(edit13.Text);
  1137.       n:=a;
  1138.      // m:=m;
  1139.       b:=strtofloat(edit12.Text);
  1140.      ll:=combobox6.ItemIndex;
  1141.       case ll of
  1142.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1143.          1:m:= b*1000.0;
  1144.          2:m:= b;
  1145.          3:m:= b/1000.0 }
  1146.           0:begin if (b<=-70) or (b>=10) then
  1147.         begin
  1148.         showmessage('输入的数值超出范围!') ;
  1149.          edit12.Text:='';
  1150.          end
  1151.         else begin
  1152.          b:=power(10,b/10.0);
  1153.           b:=b*1000.0;
  1154.           c:= b/ a;
  1155.            edit11.Text:=formatfloat('0.000',c);
  1156.           end;
  1157.           end;
  1158.          1:begin if (b>10) or (b<1/10000000) then begin
  1159.           showmessage('输入数值超出范围!');
  1160.             edit12.Text:='';
  1161.             end
  1162.          else begin b:= b*1000.0;
  1163.          c:= b/ a;
  1164.   edit11.Text:=formatfloat('0.000',c);
  1165.   end;
  1166.    end;
  1167.          2:begin if (b>1000)or (b<1/10000) then begin
  1168.           showmessage('输入数值超出范围!');
  1169.           edit12.Text:='';
  1170.           end
  1171.          else begin  b:= b;
  1172.          c:= b/ a;
  1173.   edit11.Text:=formatfloat('0.000',c);
  1174.   end;
  1175.   end;
  1176.          3:begin if (b>1000000)or (b<1/10) then begin
  1177.           showmessage('输入数值超出范围!');
  1178.              edit12.Text:='';
  1179.           end
  1180.          else begin  b:= b/1000.0;
  1181.          c:= b/ a;
  1182.   edit11.Text:=formatfloat('0.000',c);;
  1183.          end;
  1184.          end;
  1185.          end;
  1186.     //  c:= m/ n;
  1187.   //edit11.Text:=formatfloat('0.000',c);
  1188.       end;
  1189.       if str1='nw' then begin
  1190.        a:=strtofloat(edit13.Text);
  1191.       n:=a;
  1192.       a:=a/1000.0;
  1193.       b:=strtofloat(edit12.Text);
  1194.       ll:=combobox6.ItemIndex;
  1195.       case ll of
  1196.         {0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  1197.          1:m:= b*1000.0;
  1198.          2:m:= b;
  1199.          3:m:= b/1000.0  }
  1200.           0:begin if (b<=-70) or (b>=10) then
  1201.         begin
  1202.         showmessage('输入的数值超出范围!') ;
  1203.          edit12.Text:='';
  1204.          end
  1205.         else begin
  1206.          b:=power(10,b/10.0);
  1207.           b:=b*1000.0;
  1208.           c:= b/ a;
  1209.            edit11.Text:=formatfloat('0.000',c);
  1210.           end;
  1211.           end;
  1212.          1:begin if (b>10) or (b<1/10000000) then begin
  1213.           showmessage('输入数值超出范围!');
  1214.             edit12.Text:='';
  1215.             end
  1216.          else begin a:= b*1000.0;
  1217.          c:= b/ a;
  1218.   edit11.Text:=formatfloat('0.000',c);
  1219.   end;
  1220.    end;
  1221.          2:begin if (b>1000)or (b<1/10000) then begin
  1222.           showmessage('输入数值超出范围!');
  1223.           edit12.Text:='';
  1224.           end
  1225.          else begin  b:= b;
  1226.          c:= b/ a;
  1227.   edit11.Text:=formatfloat('0.000',c);
  1228.   end;
  1229.   end;
  1230.          3:begin if (b>1000000)or (b<1/10) then begin
  1231.           showmessage('输入数值超出范围!');
  1232.              edit12.Text:='';
  1233.           end
  1234.          else begin  b:= b/1000.0;
  1235.          c:= b/ a;
  1236.   edit11.Text:=formatfloat('0.000',c);;
  1237.          end;
  1238.          end;
  1239.          end;
  1240.      // c:= m/ n;
  1241.  // edit11.Text:=formatfloat('0.000',c);
  1242.       end;
  1243.       if str1='mw' then begin
  1244.         a:=strtofloat(edit13.Text);
  1245.       n:=a;
  1246.       a:=a*1000.0;
  1247.       b:=strtofloat(edit12.Text);
  1248.       ll:=combobox6.ItemIndex;
  1249.       case ll of
  1250.      {   0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1251.          1:m:= b*1000.0;
  1252.          2:m:= b;
  1253.          3:m:= b/1000.0    }
  1254.           0:begin if (b<=-70) or (b>=10) then
  1255.         begin
  1256.         showmessage('输入的数值超出范围!') ;
  1257.          edit12.Text:='';
  1258.          end
  1259.         else begin
  1260.          b:=power(10,b/10.0);
  1261.           b:=b*1000.0;
  1262.           c:= b/ a;
  1263.            edit11.Text:=formatfloat('0.000',c);
  1264.           end;
  1265.           end;
  1266.          1:begin if (b>10) or (b<1/10000000) then begin
  1267.           showmessage('输入数值超出范围!');
  1268.             edit12.Text:='';
  1269.             end
  1270.          else begin b:= b*1000.0;
  1271.          c:= b/ a;
  1272.   edit11.Text:=formatfloat('0.000',c);
  1273.   end;
  1274.    end;
  1275.          2:begin if (b>1000)or (b<1/10000) then begin
  1276.           showmessage('输入数值超出范围!');
  1277.           edit12.Text:='';
  1278.           end
  1279.          else begin  b:= b;
  1280.          c:= b/ a;
  1281.   edit11.Text:=formatfloat('0.000',c);
  1282.   end;
  1283.   end;
  1284.          3:begin if (b>1000000)or (b<1/10) then begin
  1285.           showmessage('输入数值超出范围!');
  1286.              edit12.Text:='';
  1287.           end
  1288.          else begin  b:= b/1000.0;
  1289.          c:= b/ a;
  1290.   edit11.Text:=formatfloat('0.000',c);;
  1291.          end;
  1292.          end;
  1293.          end;
  1294.   //edit11.Text:=formatfloat('0.000',c);
  1295. end;
  1296.  // end;
  1297.   end
  1298.   else
  1299.   begin
  1300.       showmessage('请先输入正确的值!');
  1301.   end;
  1302. end;
  1303. procedure TForm1.Button15Click(Sender: TObject);
  1304. var
  1305.   a,b:real;
  1306.   c: real;
  1307.  m,n:variant;
  1308.  str1:string;
  1309.  ll:integer;
  1310. begin
  1311. c:=0.00;
  1312.   if (edit15.Text<>'') and (edit16.Text<>'') then
  1313.   begin  {if (strtofloat(edit3.Text) >25.00) or(strtofloat(edit3.Text)<-45.00) then
  1314.  begin
  1315.  showmessage('数值超出合理范围(-45.00~+25.00)');     /////////////////////////////////
  1316.  edit3.Text:='';
  1317.   end else begin }
  1318.        str1:=label21.Caption;
  1319.   if str1='dBm' then  begin
  1320.       a:=strtofloat(edit16.Text);
  1321.       n:=a;
  1322.       a:=power(10,a/10.0);              //dbm to mw
  1323.       a:=a*1000.0;                       //mw to uw
  1324.       b:=strtofloat(edit15.Text);
  1325.       ll:=combobox7.ItemIndex;
  1326.       case ll of
  1327.         {0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1328.          1:m:= b*1000.0;
  1329.          2:m:= b;
  1330.          3:m:= b/1000.0   }
  1331.           0:begin if (b<=-70) or (b>=10) then
  1332.         begin
  1333.         showmessage('输入的数值超出范围!') ;
  1334.          edit15.Text:='';
  1335.          end
  1336.         else begin
  1337.          b:=power(10,b/10.0);
  1338.           b:=b*1000.0;
  1339.           c:= b/ a;
  1340.            edit14.Text:=formatfloat('0.000',c);
  1341.           end;
  1342.           end;
  1343.          1:begin if (b>10) or (b<1/10000000) then begin
  1344.           showmessage('输入的数值超出范围!');
  1345.             edit15.Text:='';
  1346.             end
  1347.          else begin b:= b*1000.0;
  1348.          c:= b/ a;
  1349.   edit14.Text:=formatfloat('0.000',c);
  1350.   end;
  1351.    end;
  1352.          2:begin if (b>1000)or (b<1/10000) then begin
  1353.           showmessage('输入的数值超出范围!');
  1354.           edit15.Text:='';
  1355.           end
  1356.          else begin  b:= b;
  1357.          c:= b/ a;
  1358.   edit14.Text:=formatfloat('0.000',c);
  1359.   end;
  1360.   end;
  1361.          3:begin if (b>1000000)or (b<1/10) then begin
  1362.           showmessage('输入的数值超出范围!');
  1363.              edit15.Text:='';
  1364.           end
  1365.          else begin  b:= b/1000.0;
  1366.          c:= b/ a;
  1367.   edit14.Text:=formatfloat('0.000',c);;
  1368.          end;
  1369.          end;
  1370.          end;
  1371.      // c:= m/ n;
  1372.  // edit14.Text:=formatfloat('0.000',c);
  1373.   end;
  1374.   if str1='uw' then begin
  1375.       a:=strtofloat(edit16.Text);
  1376.       n:=a;
  1377.      // m:=m;
  1378.       b:=strtofloat(edit15.Text);
  1379.      ll:=combobox7.ItemIndex;
  1380.       case ll of
  1381.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1382.          1:m:= b*1000.0;
  1383.          2:m:= b;
  1384.          3:m:= b/1000.0   }
  1385.           0:begin if (b<=-70) or (b>=10) then
  1386.         begin
  1387.         showmessage('输入的数值超出范围!') ;
  1388.          edit15.Text:='';
  1389.          end
  1390.         else begin
  1391.          b:=power(10,b/10.0);
  1392.           b:=b*1000.0;
  1393.           c:= b/ a;
  1394.            edit14.Text:=formatfloat('0.000',c);
  1395.           end;
  1396.           end;
  1397.          1:begin if (b>10) or (b<1/10000000) then begin
  1398.           showmessage('输入的数值超出范围!');
  1399.             edit15.Text:='';
  1400.             end
  1401.          else begin b:= b*1000.0;
  1402.          c:= b/ a;
  1403.   edit14.Text:=formatfloat('0.000',c);
  1404.   end;
  1405.    end;
  1406.          2:begin if (b>1000)or (b<1/10000) then begin
  1407.           showmessage('输入的数值超出范围!');
  1408.           edit15.Text:='';
  1409.           end
  1410.          else begin  b:= b;
  1411.          c:= b/ a;
  1412.   edit14.Text:=formatfloat('0.000',c);
  1413.   end;
  1414.   end;
  1415.          3:begin if (b>1000000)or (b<1/10) then begin
  1416.           showmessage('输入的数值超出范围!');
  1417.              edit15.Text:='';
  1418.           end
  1419.          else begin  b:= b/1000.0;
  1420.          c:= b/a;
  1421.   edit14.Text:=formatfloat('0.000',c);;
  1422.          end;
  1423.          end;
  1424.          end;
  1425.       //c:= m/ n;
  1426.   //edit14.Text:=formatfloat('0.000',c);
  1427.       end;
  1428.       if str1='nw' then begin
  1429.        a:=strtofloat(edit16.Text);
  1430.       n:=a;
  1431.       a:=a/1000.0;
  1432.       b:=strtofloat(edit15.Text);
  1433.       ll:=combobox7.ItemIndex;
  1434.       case ll of
  1435.       {  0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  1436.          1:m:= b*1000.0;
  1437.          2:m:= b;
  1438.          3:m:= b/1000.0    }
  1439.           0:begin if (b<=-70) or (b>=10) then
  1440.         begin
  1441.         showmessage('输入的数值超出范围!') ;
  1442.          edit15.Text:='';
  1443.          end
  1444.         else begin
  1445.          b:=power(10,b/10.0);
  1446.           b:=b*1000.0;
  1447.           c:= b/a;
  1448.            edit14.Text:=formatfloat('0.000',c);
  1449.           end;
  1450.           end;
  1451.          1:begin if (b>10) or (b<1/10000000) then begin
  1452.           showmessage('输入的数值超出范围!');
  1453.             edit15.Text:='';
  1454.             end
  1455.          else begin b:= b*1000.0;
  1456.          c:= b/ a;
  1457.   edit14.Text:=formatfloat('0.000',c);
  1458.   end;
  1459.    end;
  1460.          2:begin if (b>1000)or (b<1/10000) then begin
  1461.           showmessage('输入的数值超出范围!');
  1462.           edit15.Text:='';
  1463.           end
  1464.          else begin  b:= b;
  1465.          c:= b/a;
  1466.   edit14.Text:=formatfloat('0.000',c);
  1467.   end;
  1468.   end;
  1469.          3:begin if (b>1000000)or (b<1/10) then begin
  1470.           showmessage('输入的数值超出范围!');
  1471.              edit15.Text:='';
  1472.           end
  1473.          else begin  b:= b/1000.0;
  1474.          c:= b/ a;
  1475.   edit14.Text:=formatfloat('0.000',c);;
  1476.          end;
  1477.          end;
  1478.          end;
  1479.      // c:= m/ n;
  1480.   //edit14.Text:=formatfloat('0.000',c);
  1481.       end;
  1482.       if str1='mw' then begin
  1483.         a:=strtofloat(edit16.Text);
  1484.       n:=a;
  1485.       a:=a*1000.0;
  1486.       b:=strtofloat(edit15.Text);
  1487.       ll:=combobox7.ItemIndex;
  1488.       case ll of
  1489.         {0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1490.          1:m:= b*1000.0;
  1491.          2:m:= b;
  1492.          3:m:= b/1000.0   }
  1493.           0:begin if (b<=-70) or (b>=10) then
  1494.         begin
  1495.         showmessage('输入的数值超出范围!') ;
  1496.          edit15.Text:='';
  1497.          end
  1498.         else begin
  1499.          b:=power(10,b/10.0);
  1500.           b:=b*1000.0;
  1501.           c:= b/ a;
  1502.            edit14.Text:=formatfloat('0.000',c);
  1503.           end;
  1504.           end;
  1505.          1:begin if (b>10) or (b<1/10000000) then begin
  1506.           showmessage('输入的数值超出范围!');
  1507.             edit15.Text:='';
  1508.             end
  1509.          else begin b:= b*1000.0;
  1510.          c:= b/ a;
  1511.   edit14.Text:=formatfloat('0.000',c);
  1512.   end;
  1513.    end;
  1514.          2:begin if (b>1000)or (b<1/10000) then begin
  1515.           showmessage('输入的数值超出范围!');
  1516.           edit15.Text:='';
  1517.           end
  1518.          else begin  b:= b;
  1519.          c:= b/a;
  1520.   edit14.Text:=formatfloat('0.000',c);
  1521.   end;
  1522.   end;
  1523.          3:begin if (b>1000000)or (b<1/10) then begin
  1524.           showmessage('输入的数值超出范围!');
  1525.              edit15.Text:='';
  1526.           end
  1527.          else begin  b:= b/1000.0;
  1528.          c:= b/a;
  1529.   edit14.Text:=formatfloat('0.000',c);;
  1530.          end;
  1531.          end;
  1532.          end;
  1533.   //edit14.Text:=formatfloat('0.000',c);
  1534. end;
  1535.  // end;
  1536.   end
  1537.   else
  1538.   begin
  1539.       showmessage('请先输入正确的值!');
  1540.   end;
  1541. end;
  1542. procedure TForm1.Button18Click(Sender: TObject);
  1543. var
  1544.   a,b:real;
  1545.   c: real;
  1546.  m,n:variant;
  1547.  str1:string;
  1548.  ll:integer;
  1549. begin
  1550. c:=0.00;
  1551.   if (edit18.Text<>'') and (edit19.Text<>'') then
  1552.   begin  {if (strtofloat(edit3.Text) >40.00) or(strtofloat(edit3.Text)<-45.00) then
  1553.  begin
  1554.  showmessage('数值超出合理范围');     /////////////////////////////////
  1555.  edit3.Text:='';
  1556.   end else begin }
  1557.        str1:=label22.Caption;
  1558.   if str1='dBm' then  begin
  1559.       a:=strtofloat(edit19.Text);
  1560.       n:=a;
  1561.       a:=power(10,n/10.0);              //dbm to mw
  1562.       a:=a*1000.0;                       //mw to uw
  1563.       b:=strtofloat(edit18.Text);
  1564.       ll:=combobox8.ItemIndex;
  1565.       case ll of
  1566.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1567.          1:m:= b*1000.0;
  1568.          2:m:= b;
  1569.          3:m:= b/1000.0 }
  1570.           0:begin if (b<=-70) or (b>=10) then
  1571.         begin
  1572.         showmessage('输入的数值超出范围!') ;
  1573.          edit18.Text:='';
  1574.          end
  1575.         else begin
  1576.          b:=power(10,b/10.0);
  1577.           b:=b*1000.0;
  1578.           c:= b/ a;
  1579.            edit17.Text:=formatfloat('0.000',c);
  1580.           end;
  1581.           end;
  1582.          1:begin if (b>10) or (b<1/10000000) then begin
  1583.           showmessage('输入的数值超出范围!');
  1584.             edit18.Text:='';
  1585.             end
  1586.          else begin b:= b*1000.0;
  1587.          c:= b/ a;
  1588.   edit17.Text:=formatfloat('0.000',c);
  1589.   end;
  1590.    end;
  1591.          2:begin if (b>1000)or (b<1/10000) then begin
  1592.           showmessage('输入的数值超出范围!');
  1593.           edit18.Text:='';
  1594.           end
  1595.          else begin  b:= b;
  1596.          c:= b/a;
  1597.   edit17.Text:=formatfloat('0.000',c);
  1598.   end;
  1599.   end;
  1600.          3:begin if (b>1000000)or (b<1/10) then begin
  1601.           showmessage('输入的数值超出范围!');
  1602.              edit18.Text:='';
  1603.           end
  1604.          else begin  b:= b/1000.0;
  1605.          c:= b/a;
  1606.   edit17.Text:=formatfloat('0.000',c);;
  1607.          end;
  1608.          end;
  1609.          end;
  1610.      // c:= m/ n;
  1611.   //edit17.Text:=formatfloat('0.000',c);
  1612.   end;
  1613.   if str1='uw' then begin
  1614.       a:=strtofloat(edit19.Text);
  1615.       n:=a;
  1616.      // m:=m;
  1617.       b:=strtofloat(edit18.Text);
  1618.      ll:=combobox8.ItemIndex;
  1619.       case ll of
  1620.        { 0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1621.          1:m:= b*1000.0;
  1622.          2:m:= b;
  1623.          3:m:= b/1000.0  }
  1624.           0:begin if (b<=-70) or (b>=10) then
  1625.         begin
  1626.         showmessage('输入的数值超出范围!') ;
  1627.          edit18.Text:='';
  1628.          end
  1629.         else begin
  1630.          b:=power(10,b/10.0);
  1631.           b:=b*1000.0;
  1632.           c:= b/a;
  1633.            edit17.Text:=formatfloat('0.000',c);
  1634.           end;
  1635.           end;
  1636.          1:begin if (b>10) or (b<1/10000000) then begin
  1637.           showmessage('输入的数值超出范围!');
  1638.             edit18.Text:='';
  1639.             end
  1640.          else begin b:= b*1000.0;
  1641.          c:= b/ a;
  1642.   edit17.Text:=formatfloat('0.000',c);
  1643.   end;
  1644.    end;
  1645.          2:begin if (b>1000)or (b<1/10000) then begin
  1646.           showmessage('输入的数值超出范围!');
  1647.           edit18.Text:='';
  1648.           end
  1649.          else begin  b:= b;
  1650.          c:= b/ a;
  1651.   edit17.Text:=formatfloat('0.000',c);
  1652.   end;
  1653.   end;
  1654.          3:begin if (b>1000000)or (b<1/10) then begin
  1655.           showmessage('输入的数值超出范围!');
  1656.              edit18.Text:='';
  1657.           end
  1658.          else begin  b:= b/1000.0;
  1659.          c:= b/a;
  1660.   edit17.Text:=formatfloat('0.000',c);;
  1661.          end;
  1662.          end;
  1663.          end;
  1664.     //  c:= m/ n;
  1665.   //edit17.Text:=formatfloat('0.000',c);
  1666.       end;
  1667.       if str1='nw' then begin
  1668.        a:=strtofloat(edit19.Text);
  1669.       n:=a;
  1670.       a:=a/1000.0;
  1671.       b:=strtofloat(edit18.Text);
  1672.       ll:=combobox8.ItemIndex;
  1673.       case ll of
  1674.       {  0:begin m:=power(10,b/10.0); m:=m/1000.0; end;
  1675.          1:m:= b*1000.0;
  1676.          2:m:= b;
  1677.          3:m:= b/1000.0   }
  1678.           0:begin if (b<=-70) or (b>=10) then
  1679.         begin
  1680.         showmessage('输入的数值超出范围!') ;
  1681.          edit18.Text:='';
  1682.          end
  1683.         else begin
  1684.          b:=power(10,b/10.0);
  1685.           b:=b*1000.0;
  1686.           c:= b/ a;
  1687.            edit17.Text:=formatfloat('0.000',c);
  1688.           end;
  1689.           end;
  1690.          1:begin if (b>10) or (b<1/10000000) then begin
  1691.           showmessage('输入的数值超出范围!');
  1692.             edit18.Text:='';
  1693.             end
  1694.          else begin b:= b*1000.0;
  1695.          c:= b/ a;
  1696.   edit17.Text:=formatfloat('0.000',c);
  1697.   end;
  1698.    end;
  1699.          2:begin if (b>1000)or (b<1/10000) then begin
  1700.           showmessage('输入的数值超出范围!');
  1701.           edit18.Text:='';
  1702.           end
  1703.          else begin  b:= b;
  1704.          c:=b/a;
  1705.   edit17.Text:=formatfloat('0.000',c);
  1706.   end;
  1707.   end;
  1708.          3:begin if (b>1000000)or (b<1/10) then begin
  1709.           showmessage('输入的数值超出范围!');
  1710.              edit18.Text:='';
  1711.           end
  1712.          else begin  b:= b/1000.0;
  1713.          c:= b/a;
  1714.   edit17.Text:=formatfloat('0.000',c);;
  1715.          end;
  1716.          end;
  1717.          end;
  1718.     //  c:= m/ n;
  1719.   //edit17.Text:=formatfloat('0.000',c);
  1720.       end;
  1721.       if str1='mw' then begin
  1722.         a:=strtofloat(edit19.Text);
  1723.       n:=a;
  1724.       a:=a*1000.0;
  1725.       b:=strtofloat(edit18.Text);
  1726.       ll:=combobox8.ItemIndex;
  1727.       case ll of
  1728.         {0:begin m:=power(10,b/10.0); m:=m*1000.0; end;
  1729.          1:m:= b*1000.0;
  1730.          2:m:= b;
  1731.          3:m:= b/1000.0   }
  1732.           0:begin if (b<=-70) or (b>=10) then
  1733.         begin
  1734.         showmessage('输入的数值超出范围!') ;
  1735.          edit18.Text:='';
  1736.          end
  1737.         else begin
  1738.          b:=power(10,b/10.0);
  1739.           b:=b*1000.0;
  1740.           c:= b/ a;
  1741.            edit17.Text:=formatfloat('0.000',c);
  1742.           end;
  1743.           end;
  1744.          1:begin if (b>10) or (b<1/10000000) then begin
  1745.           showmessage('输入的数值超出范围!');
  1746.             edit18.Text:='';
  1747.             end
  1748.          else begin b:= b*1000.0;
  1749.          c:= b/ a;
  1750.   edit17.Text:=formatfloat('0.000',c);
  1751.   end;
  1752.    end;
  1753.          2:begin if (b>1000)or (b<1/10000) then begin
  1754.           showmessage('输入的数值超出范围!');
  1755.           edit18.Text:='';
  1756.           end
  1757.          else begin  b:= b;
  1758.          c:= b/a;
  1759.   edit17.Text:=formatfloat('0.000',c);
  1760.   end;
  1761.   end;
  1762.          3:begin if (b>1000000)or (b<1/10) then begin
  1763.           showmessage('输入的数值超出范围!');
  1764.              edit18.Text:='';
  1765.           end
  1766.          else begin  b:= b/1000.0;
  1767.          c:= b/ a;
  1768.   edit17.Text:=formatfloat('0.000',c);;
  1769.          end;
  1770.          end;
  1771.          end;
  1772.   edit17.Text:=formatfloat('0.000',c);
  1773. end;
  1774.  // end;
  1775.   end
  1776.   else
  1777.   begin
  1778.       showmessage('请先输入正确的值!');
  1779.   end;
  1780. end;
  1781. procedure TForm1.Button2Click(Sender: TObject);
  1782. var
  1783.  v,len,i,count:integer;
  1784.    tmpstr:string;
  1785.    tmpvar:variant;
  1786.    xornum:byte;
  1787.    arr:array of byte;
  1788.     f:real;
  1789. begin
  1790.   arr:=nil;
  1791.  if (edit2.Text='') then
  1792.   begin
  1793.   showmessage('无设定值!');
  1794.   end
  1795.  else begin if not mscomm1.PortOpen then begin
  1796.     showmessage('串口没有打开!');
  1797.      end else begin
  1798.       //hao add
  1799.   if not TsInputVal(edit2.Text) then
  1800.     begin
  1801.      edit2.SetFocus;
  1802.      exit
  1803.     end;
  1804.   //hao add end
  1805.      setlength(arr,9);
  1806.         f:=strtofloat(edit2.text)*1000.0;
  1807.         tmpstr:=floattostr(f);
  1808.          v:=strtoint(tmpstr);
  1809.             arr[0]:=$7e;   //soi
  1810.            arr[1]:=$10;   //ver
  1811.             arr[2]:= $04;    //length
  1812.             arr[3]:=$a1;     //cid
  1813.            arr[4]:=$00;      //datainfo
  1814.            arr[5]:=v div 256;
  1815.             arr[6]:= v mod 256   ;
  1816.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  1817.             arr[7]:=xornum;
  1818.             arr[8]:=$0d;
  1819.   // send data
  1820.               len:=length(arr);
  1821.            i:=0;
  1822.             count:=0;
  1823.             tmpvar:=vararraycreate([0,0],varbyte);
  1824.             //tmpvar[count]:=arr[i];
  1825.             //inc(count);
  1826.             //inc(i);
  1827.              while(count<=len-1)do begin
  1828.                         tmpvar[count]:=arr[i];
  1829.                         inc(count);
  1830.                         inc(i);
  1831.                         vararrayredim(tmpvar,count);
  1832.                     end;
  1833.       MSComm1.Output:=tmpvar;
  1834.       timer1.Enabled:=true;
  1835.  end;
  1836.      //while mscomm1.InBufferCount
  1837.     end;
  1838. end;
  1839. procedure TForm1.Timer1Timer(Sender: TObject);
  1840. var
  1841. i,n,m,chksum:integer;  //,timesum
  1842. arr:array of byte;
  1843. tmpvar:variant;
  1844. begin
  1845.      arr:=nil;
  1846.      chksum:=$00;
  1847.     timesum:=timesum+integer(timer1.Interval)+10;
  1848.      if timesum<900 then
  1849.       begin
  1850.         if mscomm1.InBufferCount>0 then begin
  1851.         timer1.Enabled:=false;
  1852.         timesum:=100;
  1853.           n:=mscomm1.InBufferCount;
  1854.           setlength(arr,n);
  1855.           tmpvar:=mscomm1.input;
  1856.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  1857.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  1858.         begin
  1859.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  1860.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  1861.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  1862.                if arr[n-3]=$0cc  then begin
  1863.                 showmessage('设置成功!') ;
  1864.                 //tag:=true;
  1865.                 end
  1866.                 else  if arr[n-3]=$66 then begin  //success:=true;
  1867.                 timer1.Enabled:=false;
  1868.                     showmessage('设置失败!');
  1869.                     end else begin timer1.Enabled:=false;
  1870.                     showmessage('数据包错误!');
  1871.                       end;
  1872.              end else
  1873.              begin
  1874.              timer1.Enabled:=false;
  1875.              showmessage('帧校验错误!'); //帧校验错误
  1876.               //success:=true;
  1877.               end;
  1878.        end else begin
  1879.        timer1.Enabled:=false;
  1880.       showmessage('响应数据错误!');
  1881.            //success:=true;
  1882.            end;
  1883.     end else begin
  1884.         sleep(10);
  1885.       timer1.Enabled:=true;
  1886.              end;
  1887.              end else begin
  1888.              //success:=true;
  1889.              timer1.Enabled:=false;
  1890.              timesum:=100;
  1891.              showmessage('通道0参数设定时响应超时!');
  1892.              end;
  1893. end;
  1894. procedure TForm1.FormCreate(Sender: TObject);
  1895. begin
  1896. tindexnum:=-1;
  1897. timesum:=100;
  1898. flag:=false;
  1899. success:=0;
  1900. zuhao:=-1;
  1901. tag:=0;
  1902. tagc:=0;
  1903. pc:=0;
  1904. p:=0;
  1905. {edit4.Enabled:=false;
  1906. edit7.Enabled:=false;
  1907. edit10.Enabled:=false;
  1908. edit13.Enabled:=false;
  1909. edit16.Enabled:=false;
  1910. edit19.Enabled:=false; }
  1911. edit20.Enabled:=false;
  1912. edit21.Enabled:=false;
  1913. edit22.Enabled:=false;
  1914. edit23.Enabled:=false;
  1915. edit24.Enabled:=false;
  1916. edit25.Enabled:=false;
  1917. edit26.Enabled:=false;
  1918. edit27.Enabled:=false;
  1919. edit28.Enabled:=false;
  1920. edit29.Enabled:=false;
  1921. edit30.Enabled:=false;
  1922. edit31.Visible:=false;
  1923. label8.Visible:=false;
  1924. label9.Visible:=false;
  1925. label10.Visible:=false;
  1926. label11.Visible:=false;
  1927. label12.Visible:=false;
  1928. label13.Visible:=false;
  1929. label14.Visible:=false;
  1930. label15.Visible:=false;
  1931. label16.Visible:=false;
  1932. edit29.Visible:=false;
  1933. edit30.Visible:=false;
  1934. edit27.Visible:=false;
  1935. edit28.Visible:=false;
  1936. button23.Visible:=false;
  1937. end;
  1938. procedure TForm1.Button26Click(Sender: TObject);
  1939. begin
  1940.  if messagedlg('你确定要退出吗?',mtConfirmation,[mbyes,mbno],0)=mryes then
  1941.     begin
  1942.     if mscomm1.PortOpen then begin
  1943.     mscomm1.PortOpen:=false;
  1944.     shape1.Brush.Color:=clred;
  1945.      end;
  1946.      application.Terminate;
  1947.     end;
  1948. end ;
  1949. procedure TForm1.Button27Click(Sender: TObject);
  1950.   var
  1951.   pt:boolean;
  1952.     filename,s,ed:string;
  1953.   i:integer;
  1954.    text:textfile;
  1955.    dataarr:array[1..6] of string;
  1956.   begin
  1957.       pt:=false;
  1958.     if opendialog1.Execute then
  1959.     begin  filename:=opendialog1.FileName;
  1960.        filename:=extractfilename(filename);
  1961.              if fileexists(filename)  then begin
  1962.         if edit1.Text='' then ed:='""' else ed:=edit1.Text;
  1963.          assignfile(text,filename);
  1964.          reset(text);
  1965.          try
  1966.             while not eof(text)  do
  1967.              begin
  1968.                readln(text,s);
  1969.                if s=ed  then  begin
  1970.                pt:=true;
  1971.                for i:=1 to 6 do begin
  1972.                   readln(text,s) ;
  1973.                 dataarr[i]:=s ;
  1974.                   end;
  1975.           edit20.Text:=dataarr[1];
  1976.           edit21.Text:=dataarr[2];
  1977.           edit22.Text:=dataarr[3];
  1978.           edit23.Text:=dataarr[4];
  1979.           edit24.Text:=dataarr[5];
  1980.           edit25.Text:=dataarr[6];
  1981.          if edit20.Text= edit2.Text then
  1982.             checkbox1.Checked:=true  else  checkbox1.Checked:=false;
  1983.          if edit21.Text= edit5.Text then
  1984.             checkbox2.Checked:=true  else  checkbox2.Checked:=false;
  1985.             if edit22.Text= edit8.Text then
  1986.             checkbox3.Checked:=true  else  checkbox3.Checked:=false;
  1987.             if edit23.Text= edit11.Text then
  1988.             checkbox4.Checked:=true  else  checkbox4.Checked:=false;
  1989.             if edit24.Text= edit14.Text then
  1990.             checkbox5.Checked:=true  else  checkbox5.Checked:=false;
  1991.             if edit25.Text= edit17.Text then
  1992.             checkbox6.Checked:=true  else  checkbox6.Checked:=false;
  1993.          
  1994.                 end ;
  1995.                end;
  1996.          finally
  1997.                closefile(text);
  1998.                end;
  1999.                 if pt=false then begin
  2000.                   edit20.Text:='';
  2001.                 edit21.Text:='';
  2002.                 edit22.Text:='';
  2003.                 edit23.Text:='';
  2004.                 edit24.Text:='';
  2005.                 edit25.Text:='';
  2006.                  showmessage('文件中无合适的记录!');
  2007.                  end;
  2008.             end else
  2009.             begin
  2010.                 edit20.Text:='';
  2011.                 edit21.Text:='';
  2012.                 edit22.Text:='';
  2013.                 edit23.Text:='';
  2014.                 edit24.Text:='';
  2015.                 edit25.Text:='';
  2016.                  showmessage('没有找到指定文件!');
  2017.             end;
  2018.      end;
  2019.      end;
  2020. procedure TForm1.Button5Click(Sender: TObject);
  2021. var
  2022.  v,len,i,count:integer;
  2023.    tmpstr:string;
  2024.    tmpvar:variant;
  2025.    xornum:byte;
  2026.    arr:array of byte;
  2027.     f:real;
  2028. begin
  2029. arr:=nil;
  2030.  if (edit5.Text='') then
  2031.   begin
  2032.   showmessage('无设定值!');
  2033.   end
  2034.  else begin if not mscomm1.PortOpen then begin
  2035.     showmessage('串口没有打开!');
  2036.      end else begin
  2037.       //hao add
  2038.   if not TsInputVal(edit5.Text) then
  2039.      begin
  2040.      edit5.SetFocus;
  2041.      exit
  2042.     end;
  2043.   //hao add end
  2044.      setlength(arr,9);
  2045.         f:=strtofloat(edit5.text)*1000.0;
  2046.         tmpstr:=floattostr(f);
  2047.          v:=strtoint(tmpstr);
  2048.             arr[0]:=$7e;   //soi
  2049.            arr[1]:=$10;   //ver
  2050.             arr[2]:= $04;    //length
  2051.             arr[3]:=$a1;     //cid
  2052.            arr[4]:=$01;      //datainfo
  2053.            arr[5]:=v div 256;
  2054.             arr[6]:= v mod 256   ;
  2055.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  2056.             arr[7]:=xornum;
  2057.             arr[8]:=$0d;
  2058.   // send data
  2059.               len:=length(arr);
  2060.            i:=0;
  2061.             count:=0;
  2062.             tmpvar:=vararraycreate([0,0],varbyte);
  2063.             //tmpvar[count]:=arr[i];
  2064.             //inc(count);
  2065.             //inc(i);
  2066.              while(count<=len-1)do begin
  2067.                         tmpvar[count]:=arr[i];
  2068.                         inc(count);
  2069.                         inc(i);
  2070.                         vararrayredim(tmpvar,count);
  2071.                     end;
  2072.       MSComm1.Output:=tmpvar;
  2073.       timer2.Enabled:=true;
  2074.  end;
  2075.      //while mscomm1.InBufferCount
  2076.     end;
  2077. end;
  2078. procedure TForm1.Button8Click(Sender: TObject);
  2079. var
  2080.  v,len,i,count:integer;
  2081.    tmpstr:string;
  2082.    tmpvar:variant;
  2083.    xornum:byte;
  2084.    arr:array of byte;
  2085.     f:real;
  2086. begin
  2087. arr:=nil;
  2088.  if (edit8.Text='') then
  2089.   begin
  2090.   showmessage('无设定值!');
  2091.   end
  2092.  else begin if not mscomm1.PortOpen then begin
  2093.     showmessage('串口没有打开!');
  2094.      end else begin
  2095.       //hao add
  2096.   if not TsInputVal(edit8.Text) then
  2097.      edit8.SetFocus;
  2098.   //hao add end
  2099.      setlength(arr,9);
  2100.         f:=strtofloat(edit8.text)*1000.0;
  2101.         tmpstr:=floattostr(f);
  2102.          v:=strtoint(tmpstr);
  2103.             arr[0]:=$7e;   //soi
  2104.            arr[1]:=$10;   //ver
  2105.             arr[2]:= $04;    //length
  2106.             arr[3]:=$a1;     //cid
  2107.            arr[4]:=$02;      //datainfo
  2108.            arr[5]:=v div 256;
  2109.             arr[6]:= v mod 256   ;
  2110.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  2111.             arr[7]:=xornum;
  2112.             arr[8]:=$0d;
  2113.   // send data
  2114.               len:=length(arr);
  2115.            i:=0;
  2116.             count:=0;
  2117.             tmpvar:=vararraycreate([0,0],varbyte);
  2118.             //tmpvar[count]:=arr[i];
  2119.             //inc(count);
  2120.             //inc(i);
  2121.              while(count<=len-1)do begin
  2122.                         tmpvar[count]:=arr[i];
  2123.                         inc(count);
  2124.                         inc(i);
  2125.                         vararrayredim(tmpvar,count);
  2126.                     end;
  2127.       MSComm1.Output:=tmpvar;
  2128.       timer3.Enabled:=true;
  2129.  end;
  2130.      //while mscomm1.InBufferCount
  2131.     end;
  2132. end;
  2133. procedure TForm1.Button11Click(Sender: TObject);
  2134. var
  2135.  v,len,i,count:integer;
  2136.    tmpstr:string;
  2137.    tmpvar:variant;
  2138.    xornum:byte;
  2139.    arr:array of byte;
  2140.     f:real;
  2141. begin
  2142. arr:=nil;
  2143.  if (edit11.Text='') then
  2144.   begin
  2145.   showmessage('无设定值!');
  2146.   end
  2147.  else begin if not mscomm1.PortOpen then begin
  2148.     showmessage('串口没有打开!');
  2149.      end else begin
  2150.       //hao add
  2151.   if not TsInputVal(edit11.Text) then
  2152.     begin
  2153.      edit11.SetFocus;
  2154.      exit
  2155.     end;
  2156.   //hao add end
  2157.      setlength(arr,9);
  2158.         f:=strtofloat(edit11.text)*1000.0;
  2159.         tmpstr:=floattostr(f);
  2160.          v:=strtoint(tmpstr);
  2161.             arr[0]:=$7e;   //soi
  2162.            arr[1]:=$10;   //ver
  2163.             arr[2]:= $04;    //length
  2164.             arr[3]:=$a1;     //cid
  2165.            arr[4]:=$03;      //datainfo
  2166.            arr[5]:=v div 256;
  2167.             arr[6]:= v mod 256   ;
  2168.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  2169.             arr[7]:=xornum;
  2170.             arr[8]:=$0d;
  2171.   // send data
  2172.               len:=length(arr);
  2173.            i:=0;
  2174.             count:=0;
  2175.             tmpvar:=vararraycreate([0,0],varbyte);
  2176.             //tmpvar[count]:=arr[i];
  2177.             //inc(count);
  2178.             //inc(i);
  2179.              while(count<=len-1)do begin
  2180.                         tmpvar[count]:=arr[i];
  2181.                         inc(count);
  2182.                         inc(i);
  2183.                         vararrayredim(tmpvar,count);
  2184.                     end;
  2185.       MSComm1.Output:=tmpvar;
  2186.       timer4.Enabled:=true;
  2187.  end;
  2188.      //while mscomm1.InBufferCount
  2189.     end;
  2190. end;
  2191. procedure TForm1.Button14Click(Sender: TObject);
  2192. var
  2193.  v,len,i,count:integer;
  2194.    tmpstr:string;
  2195.    tmpvar:variant;
  2196.    xornum:byte;
  2197.    arr:array of byte;
  2198.     f:real;
  2199. begin
  2200. arr:=nil;
  2201.  if (edit14.Text='') then
  2202.   begin
  2203.   showmessage('无设定值!');
  2204.   end
  2205.  else begin if not mscomm1.PortOpen then begin
  2206.     showmessage('串口没有打开!');
  2207.      end else begin
  2208.       //hao add
  2209.   if not TsInputVal(edit14.Text) then
  2210.      begin
  2211.      edit14.SetFocus;
  2212.      exit
  2213.     end;
  2214.   //hao add end
  2215.      setlength(arr,9);
  2216.         f:=strtofloat(edit14.text)*1000.0;
  2217.         tmpstr:=floattostr(f);
  2218.          v:=strtoint(tmpstr);
  2219.             arr[0]:=$7e;   //soi
  2220.            arr[1]:=$10;   //ver
  2221.             arr[2]:= $04;    //length
  2222.             arr[3]:=$a1;     //cid
  2223.            arr[4]:=$04;      //datainfo
  2224.            arr[5]:=v div 256;
  2225.             arr[6]:= v mod 256   ;
  2226.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  2227.             arr[7]:=xornum;
  2228.             arr[8]:=$0d;
  2229.   // send data
  2230.               len:=length(arr);
  2231.            i:=0;
  2232.             count:=0;
  2233.             tmpvar:=vararraycreate([0,0],varbyte);
  2234.             //tmpvar[count]:=arr[i];
  2235.             //inc(count);
  2236.             //inc(i);
  2237.              while(count<=len-1)do begin
  2238.                         tmpvar[count]:=arr[i];
  2239.                         inc(count);
  2240.                         inc(i);
  2241.                         vararrayredim(tmpvar,count);
  2242.                     end;
  2243.       MSComm1.Output:=tmpvar;
  2244.       timer5.Enabled:=true;
  2245.  end;
  2246.      //while mscomm1.InBufferCount
  2247.     end;
  2248. end;
  2249. procedure TForm1.Button17Click(Sender: TObject);
  2250. var
  2251.  v,len,i,count:integer;
  2252.    tmpstr:string;
  2253.    tmpvar:variant;
  2254.    xornum:byte;
  2255.    arr:array of byte;
  2256.     f:real;
  2257. begin
  2258. arr:=nil;
  2259.  if (edit17.Text='') then
  2260.   begin
  2261.   showmessage('无设定值!');
  2262.   end
  2263.  else begin if not mscomm1.PortOpen then begin
  2264.     showmessage('串口没有打开!');
  2265.      end else begin
  2266.       //hao add
  2267.      if not TsInputVal(edit17.Text) then
  2268.        begin
  2269.          edit17.SetFocus;
  2270.          exit
  2271.        end;
  2272.   //hao add end
  2273.        setlength(arr,9);
  2274.         f:=strtofloat(edit17.text)*1000.0;
  2275.         tmpstr:=floattostr(f);
  2276.          v:=strtoint(tmpstr);
  2277.             arr[0]:=$7e;   //soi
  2278.            arr[1]:=$10;   //ver
  2279.             arr[2]:= $04;    //length
  2280.             arr[3]:=$a1;     //cid
  2281.            arr[4]:=$05;      //datainfo
  2282.            arr[5]:=v div 256;
  2283.             arr[6]:= v mod 256   ;
  2284.             xornum:= arr[2] xor arr[3] xor arr[4] xor arr[5]xor arr[6];
  2285.             arr[7]:=xornum;
  2286.             arr[8]:=$0d;
  2287.   // send data
  2288.               len:=length(arr);
  2289.            i:=0;
  2290.             count:=0;
  2291.             tmpvar:=vararraycreate([0,0],varbyte);
  2292.             //tmpvar[count]:=arr[i];
  2293.             //inc(count);
  2294.             //inc(i);
  2295.              while(count<=len-1)do begin
  2296.                         tmpvar[count]:=arr[i];
  2297.                         inc(count);
  2298.                         inc(i);
  2299.                         vararrayredim(tmpvar,count);
  2300.                     end;
  2301.       MSComm1.Output:=tmpvar;
  2302.       timer6.Enabled:=true;
  2303.  end;
  2304.      //while mscomm1.InBufferCount
  2305.     end;
  2306. end;
  2307. procedure TForm1.Timer2Timer(Sender: TObject);
  2308. var
  2309. i,n,m,chksum:integer;  //,timesum
  2310. arr:array of byte;
  2311. tmpvar:variant;
  2312. begin
  2313.      arr:=nil;
  2314.      chksum:=$00;
  2315.     timesum:=timesum+integer(timer2.Interval)+10;
  2316.      if timesum<900 then
  2317.       begin
  2318.         if mscomm1.InBufferCount>0 then begin
  2319.         timer2.Enabled:=false;
  2320.         timesum:=100;
  2321.           n:=mscomm1.InBufferCount;
  2322.           setlength(arr,n);
  2323.           tmpvar:=mscomm1.input;
  2324.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  2325.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  2326.         begin
  2327.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];
  2328.            if (arr[n-2]=chksum)and(arr[3]=$a1) then begin
  2329.                //edit4.Text:=inttostr(arr[4]*256+arr[5]);
  2330.                  if arr[n-3]=$0cc  then begin
  2331.                 showmessage('设置成功!') ;
  2332.                 //tag:=true;
  2333.                 end
  2334.                 else if arr[n-3]=$66 then begin  //success:=true;
  2335.                 timer2.Enabled:=false;
  2336.                     showmessage('设置失败!');
  2337.                     end else begin  timer1.Enabled:=false;
  2338.                       showmessage('数据包错误!');
  2339.                       end;
  2340.              end else  begin
  2341.              timer2.Enabled:=false;
  2342.              showmessage('数据错误!'); //帧校验错误
  2343.              end;
  2344.        end else  begin
  2345.        timer2.Enabled:=false;
  2346.       showmessage('响应数据错误!');
  2347.          end;
  2348.     end else begin
  2349.         sleep(10);
  2350.       timer2.Enabled:=true;
  2351.              end;
  2352.              end else begin
  2353.               timesum:=100;
  2354.              timer2.Enabled:=false;
  2355.              showmessage('通道5参数设定响应超时!');
  2356.              end;
  2357. end;
  2358. procedure TForm1.Timer3Timer(Sender: TObject);
  2359. var
  2360. i,n,m,chksum:integer;  //,timesum
  2361. arr:array of byte;
  2362. tmpvar:variant;
  2363. begin
  2364.      timer3.Enabled:=false;
  2365.      arr:=nil;
  2366.      chksum:=$00;
  2367.     timesum:=timesum+integer(timer3.Interval)+10;
  2368.      if timesum<900 then
  2369.       begin
  2370.         if mscomm1.InBufferCount>0 then begin
  2371.          timer3.Enabled:=false;
  2372.          timesum:=100;
  2373.           n:=mscomm1.InBufferCount;
  2374.           setlength(arr,n);
  2375.           tmpvar:=mscomm1.input;
  2376.        for i:=0 to n-1 do arr[i]:=tmpvar[i];
  2377.         if (arr[0]=$7e)and(arr[1]=$10)and(arr[n-1]=$0d) then
  2378.         begin
  2379.            for m:=2 to (n-3) do chksum:=chksum xor arr[m];