Recent

Author Topic: Using list of form components aside from main unit  (Read 5518 times)

vix

  • New Member
  • *
  • Posts: 27
Using list of form components aside from main unit
« on: October 20, 2010, 09:27:56 pm »
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: [Select]
procedure CheckComponents(var list:TComponent);
var _m:TComponent;
begin
   _m:=list.FindComponent('memory');
  if (_m is TMemo) then showmessage('ok');
end;

then I use this in main unit:
Code: [Select]
CheckComponent(components);

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
Tarzan no understand what mean syntax error...
..look out for my english..

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Using list of form components aside from main unit
« Reply #1 on: October 21, 2010, 10:17:17 pm »
Code: [Select]
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...

vix

  • New Member
  • *
  • Posts: 27
Re: Using list of form components aside from main unit
« Reply #2 on: November 01, 2010, 03:57:48 pm »
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
Tarzan no understand what mean syntax error...
..look out for my english..

 

TinyPortal © 2005-2018