摘要:FindComponent 物件控制
偶而用到做個紀錄
procedure TForm1.Button1Click(Sender: TObject); var i: Integer; const NamePrefix = 'MyEdit'; begin for i := 1 to 10 do begin TEdit.Create(Self).Name := NamePrefix + IntToStr(i); with TEdit(FindComponent(NamePrefix + IntToStr(i))) do begin Left := 10; Top := i * 20; Parent := self; if(i mod 2 =0) then begin Enabled:=False; Color:=clRed; end; end; end; end; procedure TForm1.Button2Click(Sender: TObject); var txt:TEdit; I: Integer; begin for i := 1 to 10 do begin txt:= TEdit(FindComponent('MyEdit'+inttostr(I))); if txt <> nil then begin if(i mod 3 =0) then begin txt.Visible:=False; end end end; end;
參考網址 http://docwiki.embarcadero.com/CodeExamples/XE7/en/FindComponent_(Delphi)
大家一起加入blogads 賺零用錢!!