執行階段產生物件問題 |
尚未結案
|
Komuro
一般會員 發表:27 回覆:46 積分:14 註冊:2004-02-19 發送簡訊給我 |
function TForm1.GetAllFiles(SourcePath:String):Tmemo;
var
memo1:Tmemo;
sr: TSearchRec;
begin
memo1 := Tmemo.Create(nil); <==這行寫法似乎有誤???
SourcePath := IncludeTrailingBackslash(SourcePath);
if FindFirst(SourcePath '\*.*' , faAnyFile, sr) = 0 then begin
repeat
if (sr.Name <> '.') and (sr.Name <> '..') then begin
if sr.Attr <> faDirectory then begin
memo1.Lines.Append(SourcePath sr.Name);
end else begin
GetAllFiles(SourcePath sr.Name)
end;
end;
until FindNext(sr) <> 0;
end;
FindClose(sr);
result := memo1;
end;
以上是我程式中一個函數,其中要用到Memo物件,我不想在Form上手動放上
Tmemo,而是在程式中想要機動產生Memo物件的方式,但執行到memo1.Lines.Append(SourcePath sr.Name);產生錯誤訊息:control has no parent window
請各位高手指教程式要怎麼改才能正常執行?
|
Chance36
版主 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
function TForm1.GetAllFiles(SourcePath:String):Tmemo; var memo1:Tmemo; sr: TSearchRec; begin memo1 := Tmemo.Create(nil); // 如此寫法 <==這行寫法似乎有誤??? With Memo1 Do Begin Parent := Form1;(或是Panel1亦可) //錯誤訊息是指這個屬性沒設定 Width := .... ..... 設定相關屬性 End; SourcePath := IncludeTrailingBackslash(SourcePath); if FindFirst(SourcePath '\*.*' , faAnyFile, sr) = 0 then begin repeat if (sr.Name <> '.') and (sr.Name <> '..') then begin if sr.Attr <> faDirectory then begin memo1.Lines.Append(SourcePath sr.Name); end else begin GetAllFiles(SourcePath sr.Name) end; end; until FindNext(sr) <> 0; end; FindClose(sr); result := memo1; ????? Memo1.Free; // 私用物件變數要記得釋放 end;發表人 - chance36 於 2004/03/31 17:12:32 |
Komuro
一般會員 發表:27 回覆:46 積分:14 註冊:2004-02-19 發送簡訊給我 |
|
Chance36
版主 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |