Solved

With LabelObject as TLabel  -  combine with Tpanel within the same with

Posted on 2004-08-20
7
253 Views
Last Modified: 2010-04-05
Hi experts,

what i am trying to do is to combine TLabel and TPanel objects within one with.

var
   HighLightObject:TObject;
begin
   if Sender is TLabel then
       ... here i am looking for particular object and checking some things too boring to be listed
        HighLightObject:=label;

   if Sender is TPanel then
       ... the same here
       HighLightObject:=TPanel;


... now i want to basically highlight object,

if HighLightObject <> nil then
begin
   with HighLightObject as TLabel do
   begin
      HighLightShape.Top:=Top-10;
      HighLightShape.Height:=Height+20;
      HighLightShape.Left:=left-10;
      HighLightShape.Width:=Width+20;
      HighLightShape.Visible:=True;
   end;
end;

... what i don't want to do is to repeat the same for TPanel and other objects (Image,Edit,Memo,Radio,CheckBox ... )
something like this would be perfect
with HighLightObject as TLabel,TPanel,TImage .... do

now down to earth, any suggestions how can i chuck it into the same with...?

(I've given 350 points to this question, as i have spent 3 hours trying to do it... and i don't consider my self dummy)
0
Comment
Question by:FDzjuba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 200 total points
ID: 11853966
something like this... using the TControl anscestor:

var
  X:Integer;
begin
  for X:=0 to ComponentCount-1 do
  begin
    if (Components[X] is TControl) then
    begin
      (Components[X] as TControl).Top:=(Components[X] as TControl).Top-10;
      (Components[X] as TControl).Height:=(Components[X] as TControl).Height+20;
    end
  end
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 11854055
you can also specify the component names to filter out only the ones you want

  for X:=0 to ComponentCount-1 do
  begin
    if (Components[X] is TControl) then
    begin
      if ((Components[X] as TControl).Name='Label1') or
         ((Components[X] as TControl).Name='CheckBox1') then
      begin
        (Components[X] as TControl).Top:=(Components[X] as TControl).Top-10;
        (Components[X] as TControl).Height:=(Components[X] as TControl).Height+20;
      end
    end
  end
0
 
LVL 2

Assisted Solution

by:Delani
Delani earned 100 total points
ID: 11855032
I get from your post you are only trying to use the same properties of the TPanel, TLabel, and so on. The logical thing to do is casting everything only to the common ancestor, in this case TControl. The code would look something like this (based on your provided sample):

var
   HighLightObject:TControl; // *** Use TControl here, so you avoid casting later ****
begin
   if Sender is TLabel then
       ... here i am looking for particular object and checking some things too boring to be listed
        HighLightObject:=label;

   if Sender is TPanel then
       ... the same here
       HighLightObject:=TPanel;


... now i want to basically highlight object,

if HighLightObject <> nil then
begin
   with HighLightObject do // *** You can now use all properties as defined by TControl
   begin
      HighLightShape.Top:=Top-10;
      HighLightShape.Height:=Height+20;
      HighLightShape.Left:=left-10;
      HighLightShape.Width:=Width+20;
      HighLightShape.Visible:=True;
   end;
end;

I hope this helps you.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:BlackTigerX
ID: 11855138
right... you can even do:

var
   HighLightObject:TControl; // *** Use TControl here, so you avoid casting later ****
begin
   HighLightObject:=(Sender as TControl); //from now on you can use this variable to check all the common properties to all of the controls
   if Sender is TLabel then
       ... here i am looking for particular object and checking some things too boring to be listed
        //HighLightObject:=label; //you don't need this now

   if Sender is TPanel then
       ... the same here
       //HighLightObject:=TPanel; //you don't need this now

0
 
LVL 12

Accepted Solution

by:
esoftbg earned 200 total points
ID: 11856416
I think the right way is below:

var
   HighLightObject:TObject;
begin

//........................................
//........................................

  if HighLightObject <> nil then
  if (HighLightObject is TControl) then
  begin
     with (HighLightObject as TControl) do
     begin
        HighLightShape.Top:=Top-10;
        HighLightShape.Height:=Height+20;
        HighLightShape.Left:=left-10;
        HighLightShape.Width:=Width+20;
        HighLightShape.Visible:=True;
     end;
  end;
end;
0
 
LVL 7

Author Comment

by:FDzjuba
ID: 11856807
I have increased points to 500 and split them between BlackTigerX , Delani, esoftbg
0
 
LVL 2

Expert Comment

by:Delani
ID: 11860130
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question