'How to see if a Delphi component already exists in your application?
How does one test if a component exists in your current application for example if you create a dynamic radiogroup named radiogroup1 how do you check if there already is a component with the name radiogroup1?
Solution 1:[1]
type
TFrameClass=class of TFrame;
procedure TForm1.LoadFrame(CurrentFrame: TFrameClass; Name:String);
var
Reference:TFrameClass;
Instance:TFrame;
begin
Instance:=TFrame(FindComponent(Name));
if (Instance=nil) then
begin
Reference:=TFrameClass(CurrentFrame);
Instance:=Reference.Create(Self);
Instance.Align := alClient;
Instance.Parent := ClientPanel;
end
else
begin
Instance.BringToFront;
end;
end;
procedure TForm1.scGPCharGlyphButton4Click(Sender: TObject);
var FrameInternalDistribution:TFrameInternalDistribution;
begin
LoadFrame(TFrameInternalDistribution, 'FrameInternalDistribution');
end;
procedure TForm1.scGPCharGlyphButton2Click(Sender: TObject);
var
FrameInboxDistribution:TFrameInboxDistribution;
begin
LoadFrame(TFrameInboxDistribution, 'FrameInboxDistribution');
end;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aziz Nortozhiev |
