1
I have a string:
var
vMinhastring : string;
begin
vMinhastring := 'Edit1';
In my form I have a Tedit Compomente with the name Edit1. How I pass some value to my Edit1, using vMinhastring as the Component name?
vMinhastring.text := 'batatinha';
I’m trying to do this, but I’m having problems:
contElem := 1;
Rdb1:= TRadioGroup.Create(TabSheet1);
Rdb1.Parent:= TabSheet1;
Rdb1.OnExit := Validacao;
Rdb1.Name:='Rdb'+IntToStr(contElem);
Rdb1.Items.Add('C');
Edit := TMaskEdit.Create(TabSheet1);
Edit.Parent:= TabSheet1;
Edit.Name:='Edit'+IntToStr(contElem);
Edit.Clear;
Edit.EditMask := ('!99;1;');
contElem := 2;
Rdb1:= TRadioGroup.Create(TabSheet1);
Rdb1.Parent:= TabSheet1;
Rdb1.OnExit := Validacao;
Rdb1.Name:='Rdb'+IntToStr(contElem);
Rdb1.Items.Add('C');
Edit := TMaskEdit.Create(TabSheet1);
Edit.Parent:= TabSheet1;
Edit.Name:='Edit'+IntToStr(contElem);
Edit.Clear;
Edit.EditMask := ('!99;1;');
I created a trial:
procedure TFCad_AnaliseDeTendencias.Validacao(Sender: TObject);
var
name, name2 :string;
i : integer;
begin
name := TRadioGroup(Sender).Name;
name2 := '';
for i := 1 to Length(name) do
begin
if name[i] in ['0'..'9'] then
name2 := name2 + name[i];
end;
name2 := 'Edit'+name2;
TMaskEdit(FindComponent(name2)).Text := '01'; //Esta dando erro aqui.
end;
Is making a mistake of
Access Violation at address
What you need is not
Edit1.Text = vMinhastring
; ?– Pagotti
that’s not what I need.
– Tiago Casanova
You will also need to specify the type of the component. Ex: 'Edit1' of type 'Tedit'. Having this in m]aos you will work with Typecast and/or RTTI. If you need an example just ask, but if you do a search on Typecast and rtti you will understand what I am saying.
– Victor Tadashi
So it seems to me that you want to find a control dynamically in the form having only his name, that’s it?
– Pagotti
That’s right @Pagotti
– Tiago Casanova
@Victortadashi has some example, using Typecast?
– Tiago Casanova
@Tiagocasanova took his last edition and no error occurs, a revised!
– Junior Moreira
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack