AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

String2Class

Ein Thema von Sploing · begonnen am 11. Mär 2015 · letzter Beitrag vom 12. Mär 2015
 
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.440 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: String2Class

  Alt 12. Mär 2015, 13:19
Irgend ein Unterscheidungskriterium braucht der Compiler, um die richtige Methode für die gesuchte Komponente bereitzustellen.
Entweder der Name unterscheidet sich (z.B. FindComponentEdit, FindComponentComboBox, usw.) oder die Parameter:
Delphi-Quellcode:
type
  TEditClass = class of TEdit;
  TComboBoxClass = class of TComboBox;
  TRadioButtonClass = class of TRadioButton;

function FindComponent(AOwner: TComponent; AClassType: TEditClass; const AName: string): TEdit; overload;
function FindComponent(AOwner: TComponent; AClassType: TComboBoxClass; const AName: string): TComboBox; overload;
function FindComponent(AOwner: TComponent; AClassType: TRadioButtonClass; const AName: string): TRadioButton; overload;

implementation

function FindComponentType(AOwner: TComponent; AClassType: TComponentClass; const AName: string): Pointer;
begin
  Result := AOwner.FindComponent(AName);
  if Assigned(Result) and (not (TComponent(Result) is AClassType)) then
    Result := nil;
end;

function FindComponent(AOwner: TComponent; AClassType: TEditClass; const AName: string): TEdit;
begin
  Result := FindComponentType(AOwner, AClassType, AName);
end;

function FindComponent(AOwner: TComponent; AClassType: TComboBoxClass; const AName: string): TComboBox;
begin
  Result := FindComponentType(AOwner, AClassType, AName);
end;

function FindComponent(AOwner: TComponent; AClassType: TRadioButtonClass; const AName: string): TRadioButton;
begin
  Result := FindComponentType(AOwner, AClassType, AName);
end;
Delphi-Quellcode:
procedure TForm1.Test;
begin
  FindComponent(Self, TEdit, 'Edit1').Text := 'Test';
  FindComponent(Self, TComboBox, 'ComboBox1').ItemIndex := -1;
  FindComponent(Self, TRadioButton, 'RadioButton1').Checked := True;
end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz