L
lining1980
Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义了一个对话框,无论输入什么,返回字符串总为空,感觉应该没问题,真奇怪!
/////////////////
自定义对话框代码
////////////////
unit uInputDialog;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TfrmNewProject = class(TForm)
edtNewName: TEdit;
GroupBox1: TGroupBox;
bbtnOK: TBitBtn;
bbtnCancel: TBitBtn;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
function InputDialog(DefaultName,NewName:string):Boolean;
end;
var
frmNewProject: TfrmNewProject;
implementation
{$R *.dfm}
procedure TfrmNewProject.FormCreate(Sender: TObject);
begin
bbtnOK.ModalResult:=mrOK;
bbtnCancel.ModalResult:=mrCancel;
end;
function TfrmNewProject.InputDialog(DefaultName,NewName: string): Boolean;
var
frmNewProject:TfrmNewProject;
begin
NewName:=DefaultName;
Result:=False;
frmNewProject:=TfrmNewProject.Create(nil);
edtNewName.Text:=DefaultName;
try
if frmNewProject.ShowModal=mrOk then
begin
NewName:=edtNewName.Text;
Result:=True;
end;
finally
frmNewProject.Free;
end;
end;
end.
///////////////////
主程序调用
////////////////////
procedure TfrmMain.btn1Click(Sender: TObject);
var
AProjectName:string;
begin
if frmNewProject.InputDialog('新工程',AProjectName) then
ShowMessage(AProjectName);
/////////////////
自定义对话框代码
////////////////
unit uInputDialog;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TfrmNewProject = class(TForm)
edtNewName: TEdit;
GroupBox1: TGroupBox;
bbtnOK: TBitBtn;
bbtnCancel: TBitBtn;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
function InputDialog(DefaultName,NewName:string):Boolean;
end;
var
frmNewProject: TfrmNewProject;
implementation
{$R *.dfm}
procedure TfrmNewProject.FormCreate(Sender: TObject);
begin
bbtnOK.ModalResult:=mrOK;
bbtnCancel.ModalResult:=mrCancel;
end;
function TfrmNewProject.InputDialog(DefaultName,NewName: string): Boolean;
var
frmNewProject:TfrmNewProject;
begin
NewName:=DefaultName;
Result:=False;
frmNewProject:=TfrmNewProject.Create(nil);
edtNewName.Text:=DefaultName;
try
if frmNewProject.ShowModal=mrOk then
begin
NewName:=edtNewName.Text;
Result:=True;
end;
finally
frmNewProject.Free;
end;
end;
end.
///////////////////
主程序调用
////////////////////
procedure TfrmMain.btn1Click(Sender: TObject);
var
AProjectName:string;
begin
if frmNewProject.InputDialog('新工程',AProjectName) then
ShowMessage(AProjectName);