我給各位看一下對方的代碼: unit addBalance;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables,IdGlobal;type TfrmAddBalance = class(TForm) Table1: TTable; DataSource1: TDataSource; GroupBox1: TGroupBox; DBGrid1: TDBGrid; GroupBox2: TGroupBox; Label1: TLabel; id: TEdit; sum: TEdit; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } function isMoney(s:string):boolean; public { Public declarations } end;var frmAddBalance: TfrmAddBalance;implementation{$R *.dfm}procedure TfrmAddBalance.Button1Click(Sender: TObject); var i:integer; canAdd:boolean; balance,deficiency:integer; begin {检查"会员编号"} canAdd:=false; i:=strtoInt(id.Text); with table1 do begin first; while not eof do begin if fields.FieldByName('会员编号').AsInteger=i then begin canAdd:=true; break; end; next; end; end; if canAdd=false then begin messageDlg('"会员编号"输入错误,请重试!',mtWarning,[mbOk],0); abort; end; {检查"充值金额"} if isMoney(sum.Text)=false then begin messageDlg('"充值金额"输入错误,请重试!',mtWarning,[mbOk],0); abort; end; with table1 do begin edit; balance:=fields.fieldByName('结余').AsInteger; deficiency:=fields.fieldByName('欠款').AsInteger; deficiency:=deficiency-strToInt(sum.Text); if deficiency<=0 then//没有欠款了 begin balance:=0-deficiency+balance; deficiency:=0; end else balance:=0; fieldValues['结余']:=balance; fieldValues['欠款']:=deficiency; post; end; messageDlg('您现在的结余是:'+intToStr(balance)+ '元 欠款是:'+intToStr(deficiency)+'元',mtWarning,[mbOk],0); id.Text:=''; sum.Text:=''; end;function TfrmAddBalance.isMoney(s: string): boolean; var i:integer; begin if length(s)=0 then begin result:=false; exit; end; i:=1; while i<=length(s) do begin if (isNumeric(s[i])=false) and (s[i]<>'.') then begin result:=false; exit; end; i:=i+1; end; result:=true; end;end.也許能幫我找到答案!!!!
object Button1: TButton Left = 416 Top = 360 Width = 75 Height = 25 Caption = 'Button1' ModalResult = 1 //<<<<<<<<<<<<<<<<<<<<<< TabOrder = 0 end 对ShowModal的窗体,有效果~~procedure TForm1.Button2Click(Sender: TObject); begin with TForm1.Create(nil) do try ShowModal; finally Free; end; end;
Left = 416
Top = 360
Width = 75
Height = 25
Caption = 'Button1'
ModalResult = 1 //<<<<<<<<<<<<<<<<<<<<<<
TabOrder = 0
end
对ShowModal的窗体,有效果~~procedure TForm1.Button2Click(Sender: TObject);
begin
with TForm1.Create(nil) do try
ShowModal;
finally
Free;
end;
end;
Procedure Tform1.ButtonClick();
begin
form1.Close;
end;
...
Button1.onClick:=ButtonClick;
应该是:Procedure Tform1.ButtonClick(Sender:TObject);
unit addBalance;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables,IdGlobal;type
TfrmAddBalance = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
GroupBox1: TGroupBox;
DBGrid1: TDBGrid;
GroupBox2: TGroupBox;
Label1: TLabel;
id: TEdit;
sum: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function isMoney(s:string):boolean;
public
{ Public declarations }
end;var
frmAddBalance: TfrmAddBalance;implementation{$R *.dfm}procedure TfrmAddBalance.Button1Click(Sender: TObject);
var
i:integer;
canAdd:boolean;
balance,deficiency:integer;
begin
{检查"会员编号"}
canAdd:=false;
i:=strtoInt(id.Text);
with table1 do
begin
first;
while not eof do
begin
if fields.FieldByName('会员编号').AsInteger=i then
begin
canAdd:=true;
break;
end;
next;
end;
end;
if canAdd=false then
begin
messageDlg('"会员编号"输入错误,请重试!',mtWarning,[mbOk],0);
abort;
end;
{检查"充值金额"}
if isMoney(sum.Text)=false then
begin
messageDlg('"充值金额"输入错误,请重试!',mtWarning,[mbOk],0);
abort;
end;
with table1 do
begin
edit;
balance:=fields.fieldByName('结余').AsInteger;
deficiency:=fields.fieldByName('欠款').AsInteger;
deficiency:=deficiency-strToInt(sum.Text);
if deficiency<=0 then//没有欠款了
begin
balance:=0-deficiency+balance;
deficiency:=0;
end
else balance:=0;
fieldValues['结余']:=balance;
fieldValues['欠款']:=deficiency;
post;
end;
messageDlg('您现在的结余是:'+intToStr(balance)+
'元 欠款是:'+intToStr(deficiency)+'元',mtWarning,[mbOk],0);
id.Text:='';
sum.Text:='';
end;function TfrmAddBalance.isMoney(s: string): boolean;
var
i:integer;
begin
if length(s)=0 then
begin
result:=false;
exit;
end;
i:=1;
while i<=length(s) do
begin
if (isNumeric(s[i])=false) and (s[i]<>'.') then
begin
result:=false;
exit;
end;
i:=i+1;
end;
result:=true;
end;end.也許能幫我找到答案!!!!
Left = 416
Top = 360
Width = 75
Height = 25
Caption = 'Button1'
ModalResult = 1 //<<<<<<<<<<<<<<<<<<<<<<
TabOrder = 0
end
对ShowModal的窗体,有效果~~procedure TForm1.Button2Click(Sender: TObject);
begin
with TForm1.Create(nil) do try
ShowModal;
finally
Free;
end;
end;
把 Button 的
Default:=True;
ModalResult:=MrOk;
Ok了,不写一句代码,回车后关闭窗体!
Left = 416
Top = 360
Width = 75
Height = 25
Caption = 'Button1'
ModalResult = 1 //<<<<<<<<<<<<<<<<<<<<<<
TabOrder = 0
end
对ShowModal的窗体,有效果~~procedure TForm1.Button2Click(Sender: TObject);
begin
with TForm1.Create(nil) do try
ShowModal;
finally
Free;
end;
end;以上代碼中有一點疑惑最上面是button1而下面是button2 這為什麼?
我引用面的代碼如:
object Button1: TButton
Left = 416
Top = 360
Width = 75
Height = 25
Caption = 'Button1'
ModalResult = 1 //<<<<<<<<<<<<<<<<<<<<<<
TabOrder = 0
end
对ShowModal的窗体,有效果~~procedure TForm1.Button1Click(Sender: TObject);
begin
with TForm1.Create(nil) do try
ShowModal;
finally
Free;
end;
end;但是這個按鈕不能關閉窗體,但是這里還是加了button1的點擊事件代碼?請問上面代碼該分析調用呢?
2、对于TBitBtn也有两种情况:
·Kind设置为bkClose等会导致Modal窗口关闭的类型;
·或者ModalResult设置为除mrNone以外的任何一个值 ______________http://hthunter.vicp.net/
1、对于TBitBtn生效的前提是窗口是ShowModal的形式显示的;
2、对于设置Kind的情况,除bkCustom和bkHelp两个值,其他值都会导致窗口关闭 ______________http://hthunter.vicp.net/
如果有,清除。
然后就OK