写了一个函数或过程如何在任何窗体中都能调用它 ( 积分: 50 )

  • 主题发起人 主题发起人 iaboy
  • 开始时间 开始时间
I

iaboy

Unregistered / Unconfirmed
GUEST, unregistred user!
如标题
就是不要在每个窗体中都要写上这段函数或过程,日后方便修改。
procedure PrintDBGrid(DBGrid: TDBGrid;
pTitle: string);
begin
........
end;
 
如标题
就是不要在每个窗体中都要写上这段函数或过程,日后方便修改。
procedure PrintDBGrid(DBGrid: TDBGrid;
pTitle: string);
begin
........
end;
 
放在一公共单元里就行了,要调用它的单元引用此单元就可以了,呵呵.
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, PublicUnit, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintDBGrid(DBGrid1, 'adfdf');
end;

end.
///////////////////////////////////////////////////
unit PublicUnit;
// 文件名要用 Unit 名相同
interface
uses
Grids, DBGrids, // 这两个是 DBGrid用到的单元
Dialogs;
// ShowMessage ,这里用到 ShowMessage 可以删除它
procedure PrintDBGrid(DBGrid: TDBGrid;
pTitle: string);
implementation
procedure PrintDBGrid(DBGrid: TDBGrid;
pTitle: string);
begin
ShowMessage(pTitle);
end;
end.
 
谢谢!!!!!!
 
后退
顶部