13328593595 发表于 2023-8-28 15:37:23

【Delphi7】《零基础入门学习Delphi》P35用户自定义类型

我用了Edit2显示出了元音字母,唯一的缺点就是显示有重复的还不知道怎么改进,知道的麻烦告诉我一下


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
vowe1: set of Char;
str:String;
i,j:Integer;
begin
Edit2.Text :='';
vowe1:=[];
j:=Length(Edit1.Text );
for i:=1 to j do
begin
    str:=Copy(Edit1.Text ,i,1);
    if (str='a')or(str='A')then
    begin
    vowe1:=vowe1+['a'];
    Edit2.Text :=Edit2.Text +'a';
    end;
    if (str='e')or (str='E')then
    begin
    vowe1:=vowe1+['e'];
    Edit2.Text :=Edit2.Text +'e';
    end;
    if (str='i')or (str='I')then
    begin
    vowe1:=vowe1+['i'];
    Edit2.Text :=Edit2.Text +'i';
    end;
    if (str='o')or (str='O')then
    begin
    vowe1:=vowe1+['o'];
    Edit2.Text :=Edit2.Text +'o';
    end;
    if (str='u')or (str='U')then
    begin
    vowe1:=vowe1+['u'];
    Edit2.Text :=Edit2.Text +'u';
    end;
end;

if vowe1=[] then
ShowMessage('未含有元音字母') ;


end;

procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Edit1.Text :='';
end;

end.
页: [1]
查看完整版本: 【Delphi7】《零基础入门学习Delphi》P35用户自定义类型