2010-03-07 66 views

回答

0

如果我得到正確的你在做什麼,

procedure TForm1.Button1Click(Sender: TObject); 
var 
    View: TForm; 
    Memo1, Memo2: TMemo; 
    Page: TTabSheet; 
    I: Integer; 

begin 
    View:= TForm2.Create(Form1); 
    View.Parent:= PageControl1.Pages[0]; 
    View.Visible:= True; 
    View:= TForm2.Create(Form1); 
    View.Parent:= PageControl1.Pages[1]; 
    View.Visible:= True; 
// find the first memo: 
    Page:= PageControl1.Pages[0]; 
    Memo1:= nil; 
    for I:= 0 to Page.ControlCount - 1 do begin 
    if Page.Controls[I] is TForm2 then begin 
     Memo1:= TForm2(Page.Controls[I]).Memo1; 
     Break; 
    end; 
    end; 
    Page:= PageControl1.Pages[1]; 
// find the second memo: 
    Memo2:= nil; 
    for I:= 0 to Page.ControlCount - 1 do begin 
    if Page.Controls[I] is TForm2 then begin 
     Memo2:= TForm2(Page.Controls[I]).Memo1; 
     Break; 
    end; 
    end; 
    if Assigned(Memo1) then Memo1.Lines.Add('First Memo'); 
    if Assigned(Memo2) then Memo2.Lines.Add('Second Memo'); 
end; 
+0

超級!幾乎沒有修改,我設法做我想做的事:) Greate工作 – gedO 2010-03-07 22:40:10

+0

夥計們幫助我。當我只使用一個TabSheet時,一切都很順利,但是當我使用更多的時候,會給出錯誤「List index outbound of bounds(1)」。任何想法的方式? – gedO 2010-03-08 06:20:34

+0

列表索引錯誤可能是因爲您訪問帶有無效索引的Pages或Controls集合。像上面的Sergs例子一樣循環控制。循環瀏覽這樣的頁面: for I:= 0 to PageControl1.PageCount - 1 do begin (PageControl1.Pages [I] .Controls [0] as TForm2).Memo1.Lines.Add('text'); 結束; – 2010-03-08 07:06:02

3

你可以做這樣的事情:

(PageControl1.Pages[0].Controls[0] as TForm2).Memo1.Lines.Add('text'); 
+0

你能寫工作示例? – gedO 2010-03-07 22:04:18

0

我看到一個很大的問題與此代碼 - Memo2將會有完全相同與Memo1相同的值,因爲在搜索循環中沒有區別。此外,如果此代碼已完成,那麼除了頁面上的表單外,沒有任何搜索循環的理由。

VilleK的答案應該編譯並運行,我不明白你在問什麼。

+0

我想你的意思是把你的第一段作爲對Serg答案的評論,而第二段作爲對Ville答案的評論。這兩段都不是這個問題的答案。 – 2010-03-08 09:21:27

0

所以,我在你的幫助下解決了我的問題。這是我的代碼:

var 
ID, I: integer; 
Tekstas: string; 
View: TForm2; 
Memo: TMemo; 
Page: TTabSheet; 
begin 
... 
    Page := PageControl.Pages[ID]; 
    for i := 0 to Page.ControlCount - 1 do 
    begin 
    (PageControl.Pages[ID].Controls[0] as TKomp_Forma).Memo.Lines.Add('['+TimeToStr(Time)+']'+Duom[ID].Vardas+': '+Tekstas); 
    end; 
end; 

希望這有助於別人

相關問題