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
Solved

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

Posted on 2004-08-20
7
250 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 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