unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm2 = class(TForm)
    edt1: TEdit;
    edt2: TEdit;
    edt3: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form2: TForm2;
  s : string;
  a : string;
  b : string;
  c : string;
  d : Integer;implementation{$R *.dfm}
procedure TForm2.btn1Click(Sender: TObject);
begin
  s:= edt1.Text;
  if s[16] = null then  begin
    a := Copy(s,9,2);
    b := Copy(s,11,2);
  end  else
    a := Copy(s,11,2);
    b := Copy(s,13,2);  begin
    if s[16] = null then
    c := Copy(s,15,1)
    else
    c := Copy(s,18,1);
  end;   d := StrToInt(c);   edt2.Text := a + '月' + b + '日'   ;
  begin
    if d mod 2 = 0 then
    edt3.Text := '女'
    else
    edt3.Text  := '男';
  end;end;
end.程序是输入身份证号然后显示生日和性别,输入十八位的身份证没有问题,但是输入十五位的就会出现错误,"" is not a valid integer value 这个错误 ,刚刚开始学习delphi, 请大家赐教!!!

解决方案 »

  1.   


    procedure TForm1.Button1Click(Sender: TObject);
    begin
      s:= edit1.Text;
      if length(s) = 15 then
      begin
        a := Copy(s,9,2);
        b := Copy(s,11,2);
      end
      else
      begin
        a := Copy(s,11,2);
        b := Copy(s,13,2);
      end;
      if length(s) = 15 then
          c := Copy(s,15,1)
      else
          c := Copy(s,18,1);
      d := StrToInt(c);
      edit2.Text := a + '月' + b + '日'   ;
      if d mod 2 = 0 then
        edit3.Text := '女'
      else
        edit3.Text  := '男';
    end;
      

  2.   

    另外你需要判断一下
    procedure TForm2.btn1Click(Sender: TObject);
    begin
      s:= edt1.Text;
      if not( length(s) in [15,18]) then
      begin
        showmessage('不是身份证号!');
        exit;
      end;
      

  3.   

    procedure TForm2.btn1Click(Sender: TObject);
    begin
      s:= edt1.Text;
      if s[16] = null then  begin
        a := Copy(s,9,2);
        b := Copy(s,11,2);
      end  else
        a := Copy(s,11,2);

        b := Copy(s,13,2);
    错误就是上面这句。  begin
        if s[16] = null then
        c := Copy(s,15,1)
        else
        c := Copy(s,18,1);
      end;
       d := StrToInt(c);   edt2.Text := a + '月' + b + '日'   ;
      begin
        if d mod 2 = 0 then
        edt3.Text := '女'
        else
        edt3.Text  := '男';
      end;end;
      

  4.   

    错误:    if s[16] = null then
    15位字符,S[16]不是null,而是 S[16]= ' '