I can't access to TreeView if the form container is created by code lazarus / 31-LCL ---------------------------------------------------------------------- BlueIcaro · 2010-09-08 11:28 Hello, I have two forms. The second form, has a TTreeView with a few items. And a Public procedure to clear the items (called clearAll). SomeThing like this: QuoteTreeView1.Items.Clear The main form, has a button, to call "ClearAll". The program compiles ok, and runs ok. But If I remove the second form, from automatic created. And I create the form, like this: Quote FormTreeView:= TMyForm.Create(frMain);  FormTreeView.Show;    In the create event of the main form. I have FormTreeView declarated on public secction of MainForm. When the programs execute: TreeView1.Items.Clear gives me a exception. What's wrong? I have Lazarus 0.9.29 SNV:27267 Thanks /BlueIcaro ---------------------------------------------------------------------- JuhaManninen · 2010-09-08 12:38 Where and when do you create FormTreeView? It may not exist when you call TreeView1.Items.Clear. Hard to say more without seeing the code. Juha ---------------------------------------------------------------------- BlueIcaro · 2010-09-08 20:20 Hello, this is the code od unit1: Quoteunit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,   unit2; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     procedure Button1Click(Sender: TObject);     procedure FormCreate(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   F : TForm2; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   f := TForm2.Create(Form1);   F.Show; end; procedure TForm1.Button1Click(Sender: TObject); begin   With Form2 do   Begin     TreeView1.Items.Clear;   end; end; end. Lazarus shows a exception on TreeView1.Items.Clear /BlueIcaro ---------------------------------------------------------------------- BlueIcaro · 2010-09-08 20:26 Well I found the problem by my self: I wrote Quoteprocedure TForm1.Button1Click(Sender: TObject); begin   With Form2 do   Begin     TreeView1.Items.Clear;   end; end; But I shold be Quoteprocedure TForm1.Button1Click(Sender: TObject); begin   With F do //Because I created the form like this: f := TForm2.Create (Form1);   Begin     TreeView1.Items.Clear;   end; end; Thanks JuhaManninen  for you answer. /BlueIcaro