Recent

Author Topic: How to know the caption of the component in which an image is inserted?  (Read 574 times)

ReinaldoSergioPTBR

  • New Member
  • *
  • Posts: 19
How to know the caption of the component in which an image is inserted?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to know the caption of the component in which an image is inserted?
« Reply #1 on: August 14, 2019, 08:08:07 pm »
Please, specify a little better what you mean: something like a TImage inside a TPanel (for example) or like the glyph in a TBitButton?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: How to know the caption of the component in which an image is inserted?
« Reply #2 on: August 14, 2019, 08:13:29 pm »
Parent ... Owner ??? A TImage has no caption ???
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to know the caption of the component in which an image is inserted?
« Reply #3 on: August 14, 2019, 08:30:05 pm »
Parent ... Owner ??? A TImage has no caption ???

Should be Parent, if anything. And yes, TImage has a Caption property, as any other descendant of TControl.

AFAIK it's not used for anything, but it has it.

ETA: This code will return the caption of the Parent of any control (including TImage):
Code: Pascal  [Select][+][-]
  1. function GetParentCaption(const AControl: TControl): String;
  2. begin
  3.   if Assigned(AControl) and Assigned(AControl.Parent) then
  4.     Result := AControl.Parent.Caption
  5.   else
  6.     Result := '';
  7. end;

And, for completeness sake, this one from the Owner:
Code: Pascal  [Select][+][-]
  1. function GetParentCaption(const AComponent: TComponent): String;
  2. begin
  3.   if Assigned(AComponent)
  4.   and AComponent.InheritsFrom(TControl)
  5.   and Assigned(TControl(AComponent).Parent) then
  6.     Result := TControl(AComponent).Parent.Caption
  7.   else
  8.     Result := '';
  9. end;
« Last Edit: August 14, 2019, 08:43:14 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: How to know the caption of the component in which an image is inserted?
« Reply #4 on: August 14, 2019, 08:38:03 pm »
Quote
..And yes, TImage has a Caption property, as any other descendant of TControl.
You are right, I've never recognized that ... funny ...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018