Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I am working on delphi.In my project i want provide end user to create controls at runtime (like button).I must give the control to end user,so he has the ability to change the name or caption of the created control at runtime.i can create the controls at runtime.I am unable to change their names during,Please help me.

You need to understand that your properties are actually changed during run time anyway when you run your application, based on form data (made by designer) or not — it does not matter.

You also need to read about properties and understand how they work. In brief, they are methods (getter/setter) providing interface and syntax mimicking reading of the field and assigning a value to the field, that is, from the point of view of the code using the object of your class, the property looks exactly like a field. So, what you need looks like this:
//var myObject : MyClass; //if this is a stack (local) variable

myObject : MyClass; //if this is a field of some declaring class (such as the one derived from Form)
myObject = //


myObject.MyProperty = newValue;

You certainly need to read a Delphi Pascal manual, pretty much from scratch and do simple exercises to make yourself comfortable before writing advanced applications.

Share this answer
Their names are only useful in design time not runtime. When you create controls dynamically you can assign an object to it with a lot of data embedded in it(so obviously a name can be linked to that object). Also it can be reverse I mean that you can store a list of objects that have their related control reference embedded in them.
Share this answer
Hi, for your problem i can say you that when you create a control on runtime, delphi set the control's name with blank. So you can set a name to your control with this example:

myControl.Name := 'myControlName'; 

So after that if you want to work with your created control on runtime you can find your control and set or get it's properties with this code:

for i:=0 to pred(self.componentCount) do
 if sel.components[i].name = 'myControlName' then 
   self.components[i].left := 100;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900