I
icola
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟刚入门,这个问题感觉不难,但已经耗费了一上午时间了,家产不多,请不要嫌分少。
我在主窗体frmMail中调用对话框,运行总出错,不知怎么回事。
//主窗体调用代码
procedure TfrmMain.Open1Click(Sender: TObject);
var
OKRightDlg:TOKRightDlg;
MDBDir,DBName:string;
begin
MDBDir:='D/*.mdb';
OKRightDlg:=TOKRightDlg.Create(Self);
try
OKRightDlg.GetAllMDB(MDBDir)
OKRightDlg.ShowModal;
DBName:=OKRightDlg.GetMDBName;
ShowMessage(DBName);
finally
OKRightDlg.Free;
end;
end;
//对话框代码如下
unit uOpenPrtDialog;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, ComCtrls;
type
TOKRightDlg = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
GroupBox1: TGroupBox;
ListBox1: TListBox;
private
{ Private declarations }
public
procedure GetAllMDB(MDBDir:string);{ Public declarations }
function GetMDBName:string;
end;
var
OKRightDlg: TOKRightDlg;
implementation
{$R *.dfm}
{ TOKRightDlg }
uses
uMain;
procedure TOKRightDlg.GetAllMDB(MDBDir:string);
var
SearchRec:TSearchRec;
Path:string;
Attr,Found:integer;
begin
Path:=MDBDir;
Attr:=faAnyFile;
Found:=FindFirst(Path,Attr,SearchRec);
while Found=0 do
begin
ListBox1.Items.Add(SearchRec.Name);
Found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
function TOKRightDlg.GetMDBName:string;
begin
OKBtn.ModalResult:=mrOK;
CancelBtn.ModalResult:=mrCancel;
if OKRightDlg.ShowModal=mrOK then
Result:=ListBox1.Items[ListBox1.ItemIndex];
if OKRightDlg.ShowModal=mrCancel then
Result:='';
end;
end.
我在主窗体frmMail中调用对话框,运行总出错,不知怎么回事。
//主窗体调用代码
procedure TfrmMain.Open1Click(Sender: TObject);
var
OKRightDlg:TOKRightDlg;
MDBDir,DBName:string;
begin
MDBDir:='D/*.mdb';
OKRightDlg:=TOKRightDlg.Create(Self);
try
OKRightDlg.GetAllMDB(MDBDir)
OKRightDlg.ShowModal;
DBName:=OKRightDlg.GetMDBName;
ShowMessage(DBName);
finally
OKRightDlg.Free;
end;
end;
//对话框代码如下
unit uOpenPrtDialog;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, ComCtrls;
type
TOKRightDlg = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
GroupBox1: TGroupBox;
ListBox1: TListBox;
private
{ Private declarations }
public
procedure GetAllMDB(MDBDir:string);{ Public declarations }
function GetMDBName:string;
end;
var
OKRightDlg: TOKRightDlg;
implementation
{$R *.dfm}
{ TOKRightDlg }
uses
uMain;
procedure TOKRightDlg.GetAllMDB(MDBDir:string);
var
SearchRec:TSearchRec;
Path:string;
Attr,Found:integer;
begin
Path:=MDBDir;
Attr:=faAnyFile;
Found:=FindFirst(Path,Attr,SearchRec);
while Found=0 do
begin
ListBox1.Items.Add(SearchRec.Name);
Found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
function TOKRightDlg.GetMDBName:string;
begin
OKBtn.ModalResult:=mrOK;
CancelBtn.ModalResult:=mrCancel;
if OKRightDlg.ShowModal=mrOK then
Result:=ListBox1.Items[ListBox1.ItemIndex];
if OKRightDlg.ShowModal=mrCancel then
Result:='';
end;
end.