[SOLVED] How to create TCheckGroup during runtime? lazarus / 31-LCL ---------------------------------------------------------------------- CM630 · 2013-06-03 08:08 I am trying to create a TCheckGroup during runtime. The following code: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var   MyCheckGroup: TCheckGroup; begin   MyCheckGroup.Create (Form1); end;  results in ...exception class 'External: SIGSEGV', the same happens when I use MyCheckGroup.Create (self); What am I doing wrong? Edit: The same happens when I try to create a TCheckBox. ---------------------------------------------------------------------- Yogi · 2013-06-03 08:39 http://www.freepascal.org/docs-html/ref/refse32.html ---------------------------------------------------------------------- howardpc · 2013-06-03 09:05 You have to assign a Parent as well as an Owner. Try something like this: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, Forms, Controls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);     procedure FormDestroy(Sender: TObject);   private     FmyChkGrp: TCheckGroup;     function NewCheckGroup(anOwner:TComponent; aParent: TWinControl;                      aTop, aLeft: integer; const aCaption: string): TCheckGroup;   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   FmyChkGrp:= NewCheckGroup(Self, Self, 10, 20, 'My New CheckGroup'); end; procedure TForm1.FormDestroy(Sender: TObject); begin   FmyChkGrp.Free; end; function TForm1.NewCheckGroup(anOwner: TComponent; aParent: TWinControl; aTop,   aLeft: integer; const aCaption: string): TCheckGroup; begin   Result:= nil;   if Assigned(anOwner) and Assigned(aParent)    then begin      Result:= TCheckGroup.Create(anOwner);      with Result do       begin         Parent:= aParent;         Top:= aTop;         Left:= aLeft;         Caption:= aCaption;       end;    end; end; end. ---------------------------------------------------------------------- zeljko · 2013-06-03 11:17 Quote from: paskal on June 03, 2013, 10:08:47 amI am trying to create a TCheckGroup during runtime. The following code: Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var   MyCheckGroup: TCheckGroup; begin   MyCheckGroup.Create (Form1); end;  Should be 1. MyCheckGroup := TCheckGroup.Create(Form1) 2. MyCheckGroup.Parent := Form1 (or whatever) ---------------------------------------------------------------------- CM630 · 2013-06-03 11:56 Thanks, that's it: procedure TForm1.Button1Click(Sender: TObject); var   MyCheckGroup: TCheckGroup; begin   MyCheckGroup := TCheckGroup.Create(self);  //or Form1   MyCheckGroup.Parent := Self; end; In fact,  MyCheckGroup.Parent := Self; is needed only if I want to make the CheckGroup visible. Edit: I just found out that my question was so stupid... Monday I'm still sleeping, Friday I've fallen asleep. ---------------------------------------------------------------------- CM630 · 2013-06-07 07:28 Another question with creation of controls during runtime occured. Code: [Select]procedure SaveFile (FileName: string); var   saveDialog : TSaveDialog; begin          saveDialog := TSaveDialog.Create(self);       end;       results in Identifier not found "self" It works, if I do: Code: [Select]procedure [b]TFormName[/b].SaveFile (FileName: string); var   saveDialog : TSaveDialog; begin          saveDialog := TSaveDialog.Create(self);       end;       Is there a workaround? ---------------------------------------------------------------------- BigChimp · 2013-06-07 07:41 Either 1. use the syntax you wrote that works (Self refers to the form, so you cannot use it in a regular procedure, you must use it in a procedure of the form class). 2. Pass nil as owner instead of self. ---------------------------------------------------------------------- zailaiboke · 2013-08-02 09:16 Self refers to the form, so you cannot use it in a regular procedure, you must use it in a procedure of the form class). ________________________________________________ FIFA Ultimate Coins