Board index » delphi » Help referencing objects based on Sender object

Help referencing objects based on Sender object

I am trying to make a generic procedure to reference other objects based
on the Sender object.  In this case, a response from a communication
port will determine which table object must be update with a new
filter.  I was trying to build the table name and associate it with a
secondary object which could be used to modify the original objects
properties.

I have tried several approaches with this being one where the generic
object code is commented out and a case statement used to accomplish the
desire effects.

Thanks for any help.

=======================================================
procedure TForm_PVS.ReQueryData(Sender: TObject; QueryLoc: String);
var
  UnitName: String;
  UnitNum: Integer;
  FilterText: String;
  TableUnit: TObject;
begin
  UnitName := (Sender as TComm).Name;
  UnitNum := StrToInt(Copy(UnitName, Length(UnitName), 1));
  FilterText :=  '''MFU #'' = ' + QueryLoc;
{  (TableUnit as TTable) := 'Table_UNIT'+IntToStr(UnitNum);
  (TableUnit as TTable).Active := False;
  (TableUnit as TTable).Filter := FilterText;
  (TableUnit as TTable).Active := True;  }
  case UnitNum of
    1: begin
        Table_UNIT1.Active := False;
        Table_UNIT1.Filter := FilterText;
        Table_UNIT1.Active := True;
       end;
    2: begin
        Table_UNIT2.Active := False;
        Table_UNIT2.Filter := FilterText;
        Table_UNIT2.Active := True;
       end;
    3: begin
        Table_UNIT3.Active := False;
        Table_UNIT3.Filter := FilterText;
        Table_UNIT3.Active := True;
       end;
    4: begin
        Table_UNIT4.Active := False;
        Table_UNIT4.Filter := FilterText;
        Table_UNIT4.Active := True;
       end;
  end;
end;
=======================================================

Rod

 

Re:Help referencing objects based on Sender object


In article <35EAFA07.FF172...@email.mot.com>, Rodney Bevill

Quote
<Rodney_Bevill-P21...@email.mot.com> writes:
>  UnitNum := StrToInt(Copy(UnitName, Length(UnitName), 1));
>  FilterText :=  '''MFU #'' = ' + QueryLoc;
>{  (TableUnit as TTable) := 'Table_UNIT'+IntToStr(UnitNum);
>  (TableUnit as TTable).Active := False;
>  (TableUnit as TTable).Filter := FilterText;
>  (TableUnit as TTable).Active := True;  }

with (FindComponent('Table_UNIT'+IntToStr(UnitNum)) as TTable) begin
  Active := false;
  Filter := FilterText;
  Active := true;
end;

FindComponent() is a method of an Owner (usually the form) which returns one of
it's components having the specified string as a name. Because it returns a
TComponent you have to type-cast it as a table (safely unles you're sure it
really will be a TTable).

I have not tested the code but _should_ work <g>

Alan Lloyd
alangll...@aol.com

Other Threads