自定义对话框中按钮的问题(100分)

  • 主题发起人 主题发起人 lxmzm
  • 开始时间 开始时间
L

lxmzm

Unregistered / Unconfirmed
GUEST, unregistred user!
在使用自定义对话框时,对话框中的按钮点击2次才有效,不知为啥?

代码如下: 增加execute

unit Unit5;

interface

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

type
Tmydialog = class(TForm)
Panel1: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label1: TLabel;
BitBtn3: TBitBtn;
ComboBox1: TComboBox;
private
{ Private declarations }
public
text:string;
function execute:boolean;
{ Public declarations }
end;

var
mydialog: Tmydialog;

implementation

function tmydialog.execute:boolean;
begin
if showmodal=MrOK then
begin
text:=combobox1.text;
result:=true;
mydialog.close;
end;
if showmodal=MrCancel then
begin
result:=false;
mydialog.close;
end;
end;

{$R *.DFM}

end.

在form1中调用
....
uses unit5;
...

使用方式:
if mydialog.exe then
.....



 
调用过程变为:
function tmydialog.execute:boolean;
var
FModalResult: Integer;
begin
FModalResult := ShowModal;
if FModalResult=mrOK then
begin
text:=combobox1.text;
result:=true;
mydialog.close;
end;
if FModalResult=mrCancel then
begin
result:=false;
mydialog.close;
end;
end;
 
我不知道 ,不过我想知道
 
ShowModal过程调用两次,当然会出现如上情况,Execute过程中只调用ShowModal过程一次
就行了。
 
unit Unit2;

interface

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

type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
function execute:boolean;
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.DFM}


function TForm2.execute;
begin
if ShowModal = mrOK then
Result := True
else Result := False;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Close;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
Close;
end;

end.
 
多人接受答案了。
 
后退
顶部