我在delphi 7裡面加了兩個文本框和一個按鈕產生如下代碼
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
beginend;end.
現在我想做的是   在文本框Edit1裡面輸入一個字符串  然後在Button1Click裡面寫一個響應事件的代碼點擊按鈕就判斷文本框的字符串是否是有效的,只要是輸入的字符串的長度是15並且只包括0到9和大寫字母A到 Z  那輸入的字符串才算有效無效的話彈出一個錯誤對話框,正確的話把框Edit2的值設為在Edit1裡面輸入的內容先謝謝了!!!真的很急我沒接觸過delphi ,但是這裡有個delphi 程序要做一點修改麻煩大家了!先謝謝了

解决方案 »

  1.   

    function isValidStr(str: string):boolean;
    var I: integer;
    begin
      result := false;
      if Length(str) <> 15 then exit;
      for i := 1 to Length(str) do
      begin
        if not (str[i] in ['0'..'9', 'a'..'z', 'A'..'Z']) then exit;
      end;
      result := true;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     if not isValidStr(Edit1.Text) then
      ShowMessage('invalid str');
    end;
      

  2.   

    楼主把它我上面这位答者的答案入你的程序中就是,只是第二个过程,按扭事件中要这样写if isvalidstr(edit1.text) then
      edit2.text := edit1.text
    else showMessage('输入数据有误!请重新输入');
      

  3.   

    to  aiirii(ari-爱的眼睛)
        非常感謝,雖然寫這樣一個程序對你來說沒甚麼難度,但是卻幫我解決了大問題 to  mengyun5005(梦云)
        謝謝你把程序寫完整