[fpc-pascal] How do I add a TComponent to TPanel dynamically?

Michael Green myatus at googlemail.com
Wed Aug 27 15:52:15 CEST 2008


Hi Danie,

Other than what was pointed out with create/destroy, wouldn't it create 
a memory leak with the NEW?
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   if pTopCV = nil
>     then  begin
>       NEW( pTopCV );
>       pTopCV^ := TControlVolume.Create(PanelDraft);  
>   
Instead, simply do:

  if not assigned(pTopCV) then begin
    pTopCV^ := TControlVolume.Create(Paneldraft);

(Same goes for the pTopCV.next entry).

-- Mike



More information about the fpc-pascal mailing list