1 2 unit Unit1; 3 4 interface 5 6 uses 7 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 8 Dialogs, StdCtrls; 9 10 type 11 TForm1 = class(TForm) 12 Memo1: TMemo; 13 Button1: TButton; 14 procedure Button1Click(Sender: TObject); 15 procedure Button2Click(Sender: TObject); 16 private 17 { Private declarations } 18 procedure ShowHideComponent(ComponentName: string;bShow:boolean); 19 public 20 { Public declarations } 21 end; 22 23 var 24 Form1: TForm1; 25 26 implementation 27 28 {$R *.dfm} 29 30 procedure TForm1.ShowHideComponent(ComponentName: string;bShow:boolean); 31 var 32 TmpComp: TComponent; 33 begin 34 TmpComp := FindComponent(ComponentName); 35 if TmpComp <> nil then 36 if TmpComp is TControl then begin 37 if bShow then 38 TControl(TmpComp).Show 39 else 40 TControl(TmpComp).Hide; 41 end 42 end; 43 44 procedure TForm1.Button1Click(Sender: TObject); 45 begin 46 47 ShowHideComponent('MEMO1',false); 48 end; 49 50 procedure TForm1.Button1Click(Sender: TObject); 51 begin 52 53 ShowHideComponent('MEMO1',true); 54 end; 55 56 end.