回 帖 发 新 帖 刷新版面

主题:[讨论]请高手帮忙分析下语句

procedure TfrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
  tmpStr: Array [0..4069] of Char;
  myini:tinifile;
  f:string;
  s,s1:string;
  i,i1,i2,i3:integer;
begin
  //SetLength(tmpStr,BufferLength);
  tmpStr:='';
  try
  Move(Buffer^,PChar((@tmpStr)^),BufferLength);
    except
    showmessage('错误原因0');
    end;

  if Memo1.Visible then begin
  //  Memo1.Lines.Clear;
    Memo1.Lines.Add(tmpStr);
    if checkbox1.Checked  then
     begin
     f:=ExtractFilePath(Paramstr(0))+'数据.txt';
     myini:= tinifile.Create(f);
     myini.WriteString('数据','本次有效数据',inttostr(data_i)+'条') ;
     myini.WriteString('数据','数据'+inttostr(data_i),tmpstr) ;
     myini.Destroy ;
     data_i:=data_i+1;
     end;
  end;

  try
  DO_GPSString(tmpStr,GPSR1);
  ProgressBar1.Position:=gpsr1.satinfo[1].SN ;
  Label6.Caption :=inttostr(gpsr1.satinfo[1].PRN);

  ProgressBar2.Position:=gpsr1.satinfo[2].SN ;
  Label8.Caption :=inttostr(gpsr1.satinfo[2].PRN);

  ProgressBar3.Position:=gpsr1.satinfo[3].SN ;
  Label9.Caption :=inttostr(gpsr1.satinfo[3].PRN);

  ProgressBar4.Position:=gpsr1.satinfo[4].SN ;
  Label10.Caption :=inttostr(gpsr1.satinfo[4].PRN);

  ProgressBar5.Position:=gpsr1.satinfo[5].SN ;
  Label11.Caption :=inttostr(gpsr1.satinfo[5].PRN);

  ProgressBar6.Position:=gpsr1.satinfo[6].SN ;
  Label12.Caption :=inttostr(gpsr1.satinfo[6].PRN);

  ProgressBar7.Position:=gpsr1.satinfo[7].SN ;
  Label13.Caption :=inttostr(gpsr1.satinfo[7].PRN);

  ProgressBar8.Position:=gpsr1.satinfo[8].SN ;
  Label14.Caption :=inttostr(gpsr1.satinfo[8].PRN);

  ProgressBar9.Position:=gpsr1.satinfo[9].SN ;
  Label15.Caption :=inttostr(gpsr1.satinfo[9].PRN);

  ProgressBar10.Position:=gpsr1.satinfo[10].SN ;
  Label16.Caption :=inttostr(gpsr1.satinfo[10].PRN);

  ProgressBar11.Position:=gpsr1.satinfo[11].SN ;
  Label17.Caption :=inttostr(gpsr1.satinfo[11].PRN);

  ProgressBar12.Position:=gpsr1.satinfo[12].SN ;
  Label18.Caption :=inttostr(gpsr1.satinfo[12].PRN);
  except
     showmessage('错误原因1');
    end;
    
  lblJD.Caption := GPSR1.LonHemi + FloatToStr(GPSR1.Lon);
  lblWD.Caption := GPSR1.LatHemi + FloatToStr(GPSR1.Lat);
  lblHB.Caption := FloatToStr(GPSR1.Alt);
  lblTime.Caption := GPSR1.UTC;
  lblP.Caption :=FloatToStr(GPSR1.PDOP );
  LBLH.Caption :=FloatToStr(GPSR1.HDOP );
  lblv.Caption :=FloatToStr(gpsr1.VDOP );
  s:=copy(combobox1.Text ,1,2);
s1:=combobox1.Text ;
delete(s1,1,2);
i:=pos('区',s1);
i1:=strtoint(copy(s1,1,i-1));
i2:=strtoint(copy(GPSR1.UTC,1,2));
if s='东'then
  begin
    i3:=i2+i1;
    if i3>24 then i3:=i3-24;
    Label7.Caption :=inttostr(i3)+copy(GPSR1.UTC,3,4);
  end;
if s='西'then
  begin
    i3:=i1-i2;
   // if i3>24 then i3:=i3-24;
    Label7.Caption :=inttostr(i3)+copy(GPSR1.UTC,3,4);
  end;

  try

  pbxSat.Repaint;
   except
           showmessage('错误原因2');
     end;
end;
那位高手能帮我分析下代码啊··我有点读不懂··刚学delphi.能帮我写一下每段的意思嘛??拜托了····

回复列表 (共2个回复)

沙发

begin
  //SetLength(tmpStr,BufferLength);
  tmpStr:='';       //个人建议用FillChar,
  try
  Move(Buffer^,PChar((@tmpStr)^),BufferLength);    //将Buffer中的数据按照长度拷贝
    except
    showmessage('错误原因0');
    end;

  if Memo1.Visible then begin
  //  Memo1.Lines.Clear;
    Memo1.Lines.Add(tmpStr);     //在Memo中显示Buffer的内容
    if checkbox1.Checked  then
     begin
     f:=ExtractFilePath(Paramstr(0))+'数据.txt';    //将f定义为程序的第一个运行参数所指定的路径+数据.txt
     myini:= tinifile.Create(f);       //创建INI文件
     myini.WriteString('数据','本次有效数据',inttostr(data_i)+'条') ;  //向INI文件写内容,下同
     myini.WriteString('数据','数据'+inttostr(data_i),tmpstr) ;
     myini.Destroy ;  //销毁INI文件,不过建议使用Free
     data_i:=data_i+1;  //将变量data_i+1
     end;
  end;

//这以下应该是程序显示的设置,
  try
  DO_GPSString(tmpStr,GPSR1);
  ProgressBar1.Position:=gpsr1.satinfo[1].SN ;
  Label6.Caption :=inttostr(gpsr1.satinfo[1].PRN);

  ProgressBar2.Position:=gpsr1.satinfo[2].SN ;
  Label8.Caption :=inttostr(gpsr1.satinfo[2].PRN);

  ProgressBar3.Position:=gpsr1.satinfo[3].SN ;
  Label9.Caption :=inttostr(gpsr1.satinfo[3].PRN);

  ProgressBar4.Position:=gpsr1.satinfo[4].SN ;
  Label10.Caption :=inttostr(gpsr1.satinfo[4].PRN);

  ProgressBar5.Position:=gpsr1.satinfo[5].SN ;
  Label11.Caption :=inttostr(gpsr1.satinfo[5].PRN);

  ProgressBar6.Position:=gpsr1.satinfo[6].SN ;
  Label12.Caption :=inttostr(gpsr1.satinfo[6].PRN);

  ProgressBar7.Position:=gpsr1.satinfo[7].SN ;
  Label13.Caption :=inttostr(gpsr1.satinfo[7].PRN);

  ProgressBar8.Position:=gpsr1.satinfo[8].SN ;
  Label14.Caption :=inttostr(gpsr1.satinfo[8].PRN);

  ProgressBar9.Position:=gpsr1.satinfo[9].SN ;
  Label15.Caption :=inttostr(gpsr1.satinfo[9].PRN);

  ProgressBar10.Position:=gpsr1.satinfo[10].SN ;
  Label16.Caption :=inttostr(gpsr1.satinfo[10].PRN);

  ProgressBar11.Position:=gpsr1.satinfo[11].SN ;
  Label17.Caption :=inttostr(gpsr1.satinfo[11].PRN);

  ProgressBar12.Position:=gpsr1.satinfo[12].SN ;
  Label18.Caption :=inttostr(gpsr1.satinfo[12].PRN);
  except
     showmessage('错误原因1');
    end;
    
  lblJD.Caption := GPSR1.LonHemi + FloatToStr(GPSR1.Lon);
  lblWD.Caption := GPSR1.LatHemi + FloatToStr(GPSR1.Lat);
  lblHB.Caption := FloatToStr(GPSR1.Alt);
  lblTime.Caption := GPSR1.UTC;
  lblP.Caption :=FloatToStr(GPSR1.PDOP );
  LBLH.Caption :=FloatToStr(GPSR1.HDOP );
  lblv.Caption :=FloatToStr(gpsr1.VDOP );
  s:=copy(combobox1.Text ,1,2);    //将combobox1将中的内容拷贝前两个到s中
s1:=combobox1.Text ;               //将combobox1的内容符值给s1
delete(s1,1,2);                    //将s1的前两个字符删掉
i:=pos('区',s1);                   //判断s1中枢否含有‘区’字,并返回首位置
i1:=strtoint(copy(s1,1,i-1));      //从s1中拷贝i-1个字符到i1中,下一行道理相同
i2:=strtoint(copy(GPSR1.UTC,1,2));
if s='东'then
  begin
    i3:=i2+i1;
    if i3>24 then i3:=i3-24;
    Label7.Caption :=inttostr(i3)+copy(GPSR1.UTC,3,4);
  end;
if s='西'then
  begin
    i3:=i1-i2;
   // if i3>24 then i3:=i3-24;
    Label7.Caption :=inttostr(i3)+copy(GPSR1.UTC,3,4);
  end;

  try

  pbxSat.Repaint;
   except
           showmessage('错误原因2');
     end;
end;

整个函数应该是用串口接收GPS数据的处理过程,并调用了其它的处理方法。
应该不是很难理解的。

板凳

谢谢回复``帮了我大忙了``特送30分```

我来回复

您尚未登录,请登录后再回复。点此登录或注册