?
Solved

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

Posted on 2004-08-20
7
Medium Priority
?
254 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 800 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 400 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
Industry Leaders: 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 800 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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