Solved

Loading component properties

Posted on 2015-01-09
1
134 Views
Last Modified: 2015-01-13
In 'local system' I have one application running where I save component (TForm) to a file and Load it from another logged-in user.

Thereafter I want to update the Caption/Visible/Color properties every few seconds of few TLabel/TSpeedbutton/TButton.

Using (Controls... as TLabel).Caption work but not for TSpeedbutton.

I Use Delphi Xe2 on all Windows OS

Regards
Allan
0
Comment
Question by:Allan_Fernandes
1 Comment
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 40540320
Different Controls introduce the caption property at different levels of inheritance. If two components use a common ancestor's caption property then casting one component as another component will probably allow access to that component's common property.

In the case of TSpeedButton, "Caption" property is introduced at the TSpeedButton level and therefore should only be accessed by casting as TSpeedbutton.

Try something like :
if Control[I] is TSpeedButton  then
    (Control[I] as TSpeedButton).Caption := 'Blah'
else if Control[I] is TButton  then
    (Control[I] as TButton).Caption := 'Blah'
else if Control[I] is TLabel  then
    (Control[I] as TLabel).Caption := 'Blah'

Open in new window


Sure it's more code but much less likely to cause an access violation.
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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 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