- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
procedure TDetailForm.GridPanel1Click(Sender: TObject);
var
i: Integer;
s: String;
begin
//set title and subtitle
if Pos('Item', TControl(Sender).Name) > 0 then begin
if Sender.ClassName = 'TImage' then begin
i := Length(TControl(Sender).Name) - Length('ItemImage') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
ItemSubtitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end else if Pos('ItemSubTitle', TControl(Sender).Name) > 0 then begin
ItemSubtitle.Caption := TLabel(Sender).Caption;
i := Length(TControl(Sender).Name) - Length('ItemSubTitle') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
end else if Pos('ItemDescription', TControl(Sender).Name) > 0 then begin
i := Length(TControl(Sender).Name) - Length('ItemDescription') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
ItemSubtitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end else begin
ItemTitle.Caption := TLabel(Sender).Caption;
i := Length(TControl(Sender).Name) - Length('ItemTitle') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemSubTitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end;
end;
end;
Код из шаблона New Metropolis UI Application в новом Delphi XE3. Рефлексия так и прет.