[新手問題 ]StringGrid1.Cells沒有質傳入? |
尚未結案
|
rookie
一般會員 發表:26 回覆:38 積分:12 註冊:2003-04-23 發送簡訊給我 |
小弟正在寫一個檔案搜尋程式
可是值都無法傳入StringGrid1.Cells
可否請各位幫幫忙,看看哪裡寫錯
謝謝
---------------------------------------------------------------------
unit MainUnit; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ComCtrls, ExtCtrls, FileCtrl, ShellCtrls, Messages, Dialogs,
Variants; type
TPagesDlg1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
OKBtn: TButton;
CancelBtn: TButton;
HelpBtn: TButton;
Edit1: TEdit;
DriveComboBox1: TDriveComboBox;
Label1: TLabel;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
Edit2: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure FileListBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
FUNCTION SEARCH_FILE(F : STRING):INTEGER;
FUNCTION SEARCH_DIR():INTEGER;
private
{ Private declarations }
public
{ Public declarations }
end; var
PagesDlg1: TPagesDlg1;
SearchDir : String ;
implementation
Uses UNABOUT;
{$R *.dfm} procedure TPagesDlg1.FileListBox1Change(Sender: TObject); VAR FILENAME : STRING;
TF : TEXTFILE;
STR : STRING; begin
MEMO1.Lines.Clear;
Edit1.Text := SysUtils.GetCurrentDir;
FILENAME :=FileListBox1.FileName;
IF FileExists(FILENAME)= TRUE THEN
begin
AssignFile(TF,FILENAME);
RESET(TF);
While NOT EOF(TF) DO
BEGIN
READLN(TF,STR);
MEMO1.Lines.Add(STR);
End;
CloseFile(TF); END ELSE
begin
// showMessage('no file found');
end; end; procedure TPagesDlg1.Button1Click(Sender: TObject);
Var I : INTEGER;
begin IF Application.FindComponent('UNABOUT')=nil then
Application.CreateForm(TFMABOUT, FMABOUT);
I:=SEARCH_DIR();
SetCurrentDir(DirectoryListBox1.Directory);
IF I <= 0 THEN SEARCH_FILE(EDIT2.Text); {SEARCH_DIR(); }
FMABOUT.Show;
end; FUNCTION TPagesDlg1.SEARCH_DIR():INTEGER;
VAR TR : TSearchRec;
FileAttrs: Integer;
CNT: INTEGER;
BEGIN
CNT :=0;
SetCurrentDir(DirectoryListBox1.Directory);
FileAttrs :=faAnyFile;
FMABOUT.label1.Caption :=SearchDir;
with FMABOUT.StringGrid1 do
begin
Cells [0,0]:='File Name';
Cells [1,0]:='File Directory';
Cells [2,0]:='File Type(attribute)';
FMABOUT.StringGrid1.RowCount :=1;
IF FindFirst('*' , faDirectory, TR) = 0 THEN
BEGIN
REPEAT
IF ((TR.Attr = faDirectory ) AND (TR.NAME <>'.') AND (TR.NAME <>'..')) THEN
BEGIN
SetCurrentDir(TR.NAME);
RowCount := RowCount 1;
Cells[0,Rowcount -1 ]:= TR.Name;
Cells[1,Rowcount -1 ] := GetCurrentDir;
Cells[2,Rowcount -1 ] := 'directory';
SEARCH_FILE(SearchDir);
SEARCH_DIR();
INC(CNT);
END;
UNTIL FindNext(TR) <> 0;
SetCurrentDir('..');
FindClose(TR);
END;
FMABOUT.StringGrid1.FixedRows :=0;
end;
RESULT :=CNT;
END; FUNCTION TPagesDlg1.SEARCH_FILE(F : STRING):INTEGER;
VAR SR : TSearchRec;
FileAttrs: Integer;
BEGIN
FileAttrs := faAnyFile;
IF FindFirst(F , FileAttrs, SR) = 0 THEN
BEGIN
REPEAT
IF (SR.Attr and FileAttrs) = SR.Attr THEN
IF ((SR.Attr <> faDirectory )AND (SR.NAME <>'.')AND (SR.NAME <>'..')) THEN
begin
FMABOUT.StringGrid1.RowCount := FMABOUT.StringGrid1.RowCount 1;
FMABOUT.StringGrid1.Cells[0,FMABOUT.StringGrid1.Rowcount -1 ] := SR.Name;
FMABOUT.StringGrid1.Cells[1,FMABOUT.StringGrid1.Rowcount -1 ] := GetCurrentDir;
FMABOUT.StringGrid1.Cells[2,FMABOUT.StringGrid1.Rowcount -1 ] := 'directory';
end;
UNTIL FindNext(SR) <> 0;
FindClose(SR);
END;
END;
end.
----------------------------------------------------------------------
unit UNABOUT; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, Grids; type
TFMABOUT = class(TForm)
OKBtn: TButton;
Bevel1: TBevel;
Label1: TLabel;
StringGrid1: TStringGrid;
{ procedure StringGrid1Click(Sender: TObject);}
private
{ Private declarations }
public
{ Public declarations } end; var
FMABOUT: TFMABOUT;
implementation
Uses MainUnit;
{$R *.DFM}
{
end.
-------------------------------------------------------------------
program Project3; uses
Forms,
MainUnit in 'MainUnit.pas' {PagesDlg1},
UNABOUT in 'UNABOUT.PAS' {FMABOUT}; {$R *.res} begin
Application.Initialize;
Application.CreateForm(TPagesDlg1, PagesDlg1);
Application.CreateForm(TFMABOUT, FMABOUT);
// Application.CreateForm(TFMABOUT, FMABOUT);
Application.Run;
end.
------------------------------------------------------------------- 發表人 - rookie 於 2003/04/24 17:15:13 發表人 - rookie 於 2003/04/24 17:33:56 發表人 - rookie 於 2003/04/24 17:52:30 發表人 - rookie 於 2003/04/24 17:58:45
|
rookie
一般會員 發表:26 回覆:38 積分:12 註冊:2003-04-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |