我做一个可户系统,其中的客户单位资料部门有添加,修改,查询,作废,封锁,客户成员查询等功能。在实现以上除添加以外的功能的时候都需要先用一个简单的查询界面将符合条件的资料查出,而这个查询界面都是一样的。我以前用VFP的时候可将该界面作成一个组件,调用的时候给该FORM传递一个参数(比如它需要调用的FORM的名称)通过宏代换命令便可实现需要的功能。但在DELPHI中能否给FORM传递参数呢?这个问题该如何较好的解决问题?(可以定义一个全局变量来解决该问题,但这样感觉容易出问题,而且也不能随心所欲的调用任何FORM,而必须一一对应的来解决。)
解决方案 »
- 求购<DELPHI面向对象编程思想> 作者刘艺
- 关于父类与子类的一点疑问、
- Tchart 效果图
- 大侠请进:有关局域网copy文件?
- 如何将最小化的图标放在windows的状态下,并会继续在工作的
- 各位delphier,delphi的爸爸作了一个和Dephi一样好用而且比java还要快些的东东,为什么不试试呢??
- 在B/S中,如何将用户查询的结果以曲线图的形式显示?如果不用COM,有没有其他方法?
- 制作安装程序的问题
- 用ADOQuery1在一指定位置插入一记录怎么该记录增加到了最后位置?
- 字符串的处理问题!
- 怎么解决provider not find错误?
- 窗口有两个重叠的image控件,如何控制它们在上面在下面?
procedure DBGridFindFirst(const DBGrid: TDBGrid);
const
mcHorzMargin = 8;
mcVertMargin = 8;
mcHorzSpacing = 10;
mcVertSpacing = 10;
mcButtonWidth = 50;
mcButtonHeight = 14;
mcButtonSpacing = 4;
var
i: integer;
Edit: TEdit;
DialogUnits: TPoint;
HorzMargin, VertMargin: Integer;
ButtonTop: Integer;
begin
// if DBGrid1.DataSource.DataSet.FieldCount < 1 then Exit;
DaTaSetFind := Dbgrid.DataSource.DataSet;
HaveFind := False;
FindBookMark := nil;
Form := TForm.Create(Application);
set_cansel := False;
with Form do
try
Caption := GetMsg(109);
Canvas.Font := Font;
ClientWidth := Screen.Width * 2 div 5;
DialogUnits := GetAveCharSize(Canvas);
HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4);
VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8);
BorderStyle := bsDialog;
BorderIcons := [];
Position := poScreenCenter;
ButtonTop := VertMargin;
for i := 0 to DBGrid.Columns.Count - 1 do
begin
if not DBGrid.Columns[i].Visible then Continue;
with TLabel.Create(Form) do
begin
Parent := Form;
AutoSize := True;
WordWrap := False;
Caption := DBGrid.Columns[i].Title.Caption;
Left := HorzMargin;
Top := ButtonTop;
Width := Form.ClientWidth div 2 - Left + DialogUnits.x;
Height := Max(23, Height);
Layout := TlCenter;
end;
Edit := TEdit.Create(Form);
with Edit do
begin
Name := DBGrid.Columns[i].FieldName; // 'Edit'+IntToStr(i);
Parent := Form;
//TabOrder := i;
Top := ButtonTop;
Left := Form.ClientWidth div 2 + DialogUnits.x;
Width := Form.ClientWidth - Left - HorzMargin;
Height := Max(23, Height);
MaxLength := 255;
ButtonTop := ButtonTop + Height + DialogUnits.y div 2; //VertSpacing;
Text := '';
end;
end;
ButtonTop := ButtonTop + DialogUnits.y div 2;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := GetMsg(990);
//ModalResult := mrOk;
// Default := True;
Top := ButtonTop;
Width := 75;
Height := 23;
Left := (Form.ClientWidth - 2 * Width) div 6;
OnClick := TForm1(Form).BtbOkClick;
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := GetMsg(987);
//ModalResult := mrOk;
// Default := True;
Top := ButtonTop;
Width := 75;
Height := 23;
Left := (Form.ClientWidth - 2 * Width) div 6 * 4;
OnClick := TForm1(Form).BtbPrevClick;
end;
with TButton.Create(Form) do
begin
Name := 'btbClose';
Parent := Form;
Caption := GetMsg(116);
//ModalResult := mrCancel;
Cancel := True;
Top := ButtonTop;
Width := 75;
Height := 23;
Left := Width + (Form.ClientWidth - 2 * Width) div 6 * 5;
ButtonTop := Top + Height;
OnClick := TForm1(Form).BtbCloseClick;
end;
ClientHeight := ButtonTop + VertMargin div 2;
KeyPreview := True;
OnKeyPress := TForm1(Form).FormKeyPress;
ShowModal;
{if ShowModal = mrOk then
if strFieldName <> '' then
try
if not DBGrid.DataSource.DataSet.Locate(strFieldName, strFieldValue,
[loCaseInsensitive]) then HintMsg(3, 53)
except
HintMsg(1, 108);
end; }
finally
Form.Free;
end;
end;procedure TForm1.BtbPrevClick(Sender: TObject);
var
I: Integer;
begin
....
end;procedure TForm1.BtbOkClick(Sender: TObject);
var
i: Integer;
begin
.....
end;procedure TForm1.BtbCloseClick(Sender: TObject);
begin
Close;
end;
type
TForm1 = class(TForm)
private
procedure BtbOkClick(Sender: TObject);
procedure BtbPrevClick(Sender: TObject);
procedure BtbCloseClick(Sender: TObject);
end;
form1 form1-1 修改数据
form2 form2-1 查询数据
form3 form3-1 作废该记录
form4 form4-1 封锁该记录
form5 form5-1 查询属于他的子记录——————————————————-——————
以上的出口中form1至form5的界面和功能是完全一样的,只是最后他们打开的窗口不一样而已。也就是只有里面的BUTTON1CLICK的内容不一样。如果重复创建5个同样的表好象效率太底了啊。如何能简化代码?在VFP中常常是这样做的。do form with form1-1(被调用的表名)然后在form中接受参数。在button1click中写入如下代码:
//假设接收到的参数被指定到变量 mFormName,即mFormName="form1-1"了。thisform.release
do &mFormName //"&"是宏带换命令,相当于执行了: do form1-1
至于调用窗口嘛,你在Uses中加入公用窗口的引用,然后在显示公用窗口前用“公用窗口.标识变量名:=值”来赋值,再显示。另外,其实如果你只是为了实现查询,可以在Query中加几个参数呀!!!更简单!!
我想知道的是在查询窗口的ONCLICK中如何动态的调用目标窗口?
总不能用CASE吧?那样我每添加一个功能便需要修改查询窗口的代码了。
或许是我的方法不对。
TForm1 = class(TForm)
private
procedure BtbOkClick(Sender: TObject);
procedure BtbPrevClick(Sender: TObject);
procedure BtbCloseClick(Sender: TObject);
public
FrmName : string;
end;onFromshow里面加入代码判断就行了if FrmName = 'Frm1_1' then
...
....