Solved

Loading component properties

Posted on 2015-01-09
1
135 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
[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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Title # Comments Views Activity
how to center only a line in richedit? 4 79
Convert a string into a TDateTime 5 81
how can i search if string exist in array ? 3 80
DBCtrlGrid, Delphi, Scroll 7 35
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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