Board index » delphi » create components dynamically

create components dynamically

I need to create components (a series of labels) on a form dynamically.
 My code does not seem to show anything on the form..
Any help would be appreciated.
Dan.R.Metz...@noaa.gov

var
  formSearchPlotLegend: TformSearchPlotLegend;
  legendItemArray: Array of TLabel;
  numlegendItems: Integer;

procedure TformSearchPlotLegend.add_legend_item(aitemstr: String;
aitemcolor: Tcolor; aitemtag:String);
begin
  Inc(numLegendItems);
  SetLength(legendItemArray, numLegendItems);
  legendItemArray[numLegendItems-1] := TLabel.Create(Self);
  legendItemArray[numLegendItems-1].Top := (numLegendItems-1) * 20;
  legendItemArray[numLegendItems-1].Left := (numLegendItems-1) * 0;
  legendItemArray[numLegendItems-1].Width := 75;
  legendItemArray[numLegendItems-1].Height := 20;
  legendItemArray[numLegendItems-1].Caption := aitemstr;
end;

 

Re:create components dynamically


You forgot to set the parent. I believe this is in this newsgroup's MiniFaq.

Quote
>   legendItemArray[numLegendItems-1] := TLabel.Create(Self);

     legendItemArray[numLegendItems-1].parent := self;

Quote
>   legendItemArray[numLegendItems-1].Top := (numLegendItems-1) * 20;
>   legendItemArray[numLegendItems-1].Left := (numLegendItems-1) * 0;
>   legendItemArray[numLegendItems-1].Width := 75;
>   legendItemArray[numLegendItems-1].Height := 20;
>   legendItemArray[numLegendItems-1].Caption := aitemstr;
> end;

Cheers,
Nick

Re:create components dynamically


Quote
"Nicholas Sherlock" <n_sherl...@hotmail.com> wrote in message

news:ah4gvs$6hg$1@lust.ihug.co.nz...
Quote
> You forgot to set the parent. I believe this is in this newsgroup's

MiniFaq.

It is: http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm

Other Threads