Recent

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

ReinaldoSergioPTBR

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

lucamar

  • Hero Member
  • *****
  • Posts: 1960
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 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

RAW

  • Hero Member
  • *****
  • Posts: 783
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) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1

lucamar

  • Hero Member
  • *****
  • Posts: 1960
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 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

RAW

  • Hero Member
  • *****
  • Posts: 783
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) And Windows XP Pro (x86 Sp3) - LAZARUS 2.0.4 FPC 3.0.4 - TRUNK 2.1.0 FPC 3.3.1