我在主FORM1上有一个EDIT1,一个BUTTON1,我想点击这个BUTTON,出现一个NEW FORM2,在FORM2上有一个EDIT2,一个BUTTON2,一个DBGRID,想在EDIT2里输入姓名,在DBGRID里显示过滤后姓名等于EDIT2.TEXT的纪录,再DBGRID双击该纪录,关闭此FORM,回到主FORM,主FORM的EDIT1中显示选定纪录的某个字段的值。
第二个问题,是我的时间表示在库里是用20040401这样文本表示,那么,若我想计算明后两天的日期,要怎么计算才不容易出错。
因为我对DELPHI手生,所以需要一点代码。
请求大家帮忙解答,需要加分的,我会再加,
7 个解决方案
#1
第一:定义全局变量
第二:s:=copy(s,1,4)+'-'+copy(s,5,2)+'-'+copy(s,7,2);
aDate:=strtodate(s);
TmDate:=aDate+1;
AtmDate:=adate+2;
第二:s:=copy(s,1,4)+'-'+copy(s,5,2)+'-'+copy(s,7,2);
aDate:=strtodate(s);
TmDate:=aDate+1;
AtmDate:=adate+2;
#2
1 可以采用两个窗体调用一个ado控件的方法。
2 aDate :=strtodate('20040401')
strDate := formatdatetime('YYYYMMDD',(aDate+2))
2 aDate :=strtodate('20040401')
strDate := formatdatetime('YYYYMMDD',(aDate+2))
#3
关键是有没有人可以回答第一题的,帮忙一下,现出一点代码,让我看一下,好吗,因为,说我也会,就是动手这方面差劲,不好意思
#4
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
S:String;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Form2) then
begin
Form2:=TForm2.Create(Application);
Form2.ShowModal;
S:=Edit1.text;
end;
end;
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2:=nil;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
S:String;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Form2) then
begin
Form2:=TForm2.Create(Application);
Form2.ShowModal;
S:=Edit1.text;
end;
end;
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2:=nil;
end;
#5
procedure TForm.Button1OnClick(Sender: TObject);
var
Form :TForm2 ;
begin
Form := nil;
try
Form := TForm2.Create(self);
Form.ShowModal;
finally
Form.Free;
end;
end;
var
Form :TForm2 ;
begin
Form := nil;
try
Form := TForm2.Create(self);
Form.ShowModal;
finally
Form.Free;
end;
end;
#6
在窗口form2的如下事件里写
procedure TForm.formShow(Sender:TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('Select * from table where name='''+Form1.S+''');
ADOQuery.open;
end;
以上是最简单的写法 具体实现的时候还要看你的具体情况!
#7
你所谓的时间处理!最好保存的为时间日期类型
#1
第一:定义全局变量
第二:s:=copy(s,1,4)+'-'+copy(s,5,2)+'-'+copy(s,7,2);
aDate:=strtodate(s);
TmDate:=aDate+1;
AtmDate:=adate+2;
第二:s:=copy(s,1,4)+'-'+copy(s,5,2)+'-'+copy(s,7,2);
aDate:=strtodate(s);
TmDate:=aDate+1;
AtmDate:=adate+2;
#2
1 可以采用两个窗体调用一个ado控件的方法。
2 aDate :=strtodate('20040401')
strDate := formatdatetime('YYYYMMDD',(aDate+2))
2 aDate :=strtodate('20040401')
strDate := formatdatetime('YYYYMMDD',(aDate+2))
#3
关键是有没有人可以回答第一题的,帮忙一下,现出一点代码,让我看一下,好吗,因为,说我也会,就是动手这方面差劲,不好意思
#4
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
S:String;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Form2) then
begin
Form2:=TForm2.Create(Application);
Form2.ShowModal;
S:=Edit1.text;
end;
end;
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2:=nil;
end;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
S:String;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Form2) then
begin
Form2:=TForm2.Create(Application);
Form2.ShowModal;
S:=Edit1.text;
end;
end;
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
Form2:=nil;
end;
#5
procedure TForm.Button1OnClick(Sender: TObject);
var
Form :TForm2 ;
begin
Form := nil;
try
Form := TForm2.Create(self);
Form.ShowModal;
finally
Form.Free;
end;
end;
var
Form :TForm2 ;
begin
Form := nil;
try
Form := TForm2.Create(self);
Form.ShowModal;
finally
Form.Free;
end;
end;
#6
在窗口form2的如下事件里写
procedure TForm.formShow(Sender:TObject);
begin
ADOQuery.Close;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('Select * from table where name='''+Form1.S+''');
ADOQuery.open;
end;
以上是最简单的写法 具体实现的时候还要看你的具体情况!
#7
你所谓的时间处理!最好保存的为时间日期类型