Solved

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

Posted on 2004-08-20
7
246 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:BlackTigerX
Comment Utility
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
Comment Utility
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
Comment Utility
I have increased points to 500 and split them between BlackTigerX , Delani, esoftbg
0
 
LVL 2

Expert Comment

by:Delani
Comment Utility
Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now