Forum > General

Using list of form components aside from main unit

(1/1)

vix:
May I ask You a question? :)

Ok, I created a new project, then I added to this project a new unit (unit2.pas). I put some components on a form (i.e. memo, label etc.). Now i want to create a procedure in unit2 which will check if there is a specified name component on a main form. But I don't want to add unit1 (main unit) to uses list in unit2. I try to build more universal procedure, which i can use in other programs, so i want to use list of main form components as a parameter of my procedure.

Now I have something like that:

In unit2.pas:

--- Code: ---procedure CheckComponents(var list:TComponent);
var _m:TComponent;
begin
   _m:=list.FindComponent('memory');
  if (_m is TMemo) then showmessage('ok');
end;

--- End code ---

then I use this in main unit:

--- Code: ---CheckComponent(components);

--- End code ---

But it does not work, the "unit1.pas(34,19) Error: Wrong number of parameters specified for call to "GetComponent" error raise.

So how to put a list of any form components into a procedure to work on it?

I will be grateful :) Thank you!

Best regards

ivan17:

--- Code: ---procedure CheckComponents(var owner: TWinControl);
var i: integer;
begin
   for i := 0 to owner.ControlCount-1 do
      if owner.Controls[i] is TMemo then
         ShowMessage('found a memo with ' + IntToStr((owner.Controls[i] as TMemo).Lines.Count) + ' lines');
end;        // call:  CheckComponents(Form1)    or Panel1 or TabSheet2...

--- End code ---

vix:
It took me quite long time, but finally i had posibility to check it :) ant it works fine :)

Thanks ivan17 for your help!

Best regards

Navigation

[0] Message Index

Go to full version