delphi - FindComponent doens't work in a procedure -


i developing program calculates averages of datas in different tstringgrid , thought use procedure. called calcola.

procedure calcola(numero:shortint; stringgrid:tstringgrid; pbarprog:shortint); var i,j,cont,num:shortint;     avg,temp,numfl:double;     a:string;     edit1:tedit; begin if stringgrid.colcount>1   //other code         avg:=temp/cont;        tlabel(findcomponent('label'+inttostr(num))).caption:=floattostrf(avg, ffgeneral, 1, 1);        edit1.text:=floattostr(strtofloat(tlabel(findcomponent('label'+inttostr(num))).caption)*10);        tprogressbar(findcomponent('progressbar'+inttostr(i+pbarprog))).position:=strtoint(edit1.text);         //other code       end;    end; end;  

in procedure lazarus tells me "identifier not found findcomponent". cut/pasted same code in procedure tform1.button1click(sender: tobject); , had no errors.

i need use findcomponent() inside calcola, how it?

then cut/pasted same code in procedure tform1.button1click(sender: tobject); , had no errors.

the reason compiler stopped complaining when made change when calcola declared method of tform1, compiler resolve identifier findcomponent searching backwards through declared methods of tform1 , public methods of objects descends (tform ... tobject) until finds 1 declared name. findcomponent declared in tcomponent.

the reason compiler complained original version calcola declared (i assume) in program's global scope stand-alone routine , those, compiler searches through declared stand-alone procedures/functions, not ones declared methods of objects.

if whatever reason calcola procedure absolutely has stand-alone procedure, best thing adjust parameters can pass specific instance of tform1 parametet, have stringgrid.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -