unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Menus, Grids;
type
TForm1 = class(TForm)
Timer1: TTimer;
Panel1: TPanel;
Button1: TButton;
ComboBox1: TComboBox;
Label1: TLabel;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
PopupMenu1: TPopupMenu;
FormKaydet1: TMenuItem;
FormA1: TMenuItem;
Yeni1: TMenuItem;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKaydet1Click(Sender: TObject);
procedure FormA1Click(Sender: TObject);
procedure Yeni1Click(Sender: TObject);
procedure Panel1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure tiklama(Sender: TObject);
procedure tusbasimi(Sender: TObject; var Key: Char);
procedure metin_cikisi(Sender: TObject);
procedure metne_giris(Sender: TObject);
end;
var
Form1: TForm1;
butt,labe,edit:integer;
implementation
{$R *.DFM}
procedure TForm1.metin_cikisi(Sender: TObject);
begin
caption:='Form1';
end;
procedure Tform1.metne_giris (Sender: TObject);
var temp:TEdit;
begin
temp:=sender as TEdit;
caption:=temp.Text;
end;
procedure Tform1.tusbasimi (Sender: TObject; var Key: Char);
var temp:TEdit;
begin
temp:=sender as TEdit;
caption:=temp.Text+key;
end;
procedure Tform1.tiklama (Sender: TObject);
begin
if sender is TButton then
ShowMessage('Düğme Tıklandı!...');
if sender is TLabel then
ShowMessage('Etiket Tıklandı!...');
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Dugmemiz: TButton;Etiket:TLabel;Metin:TEdit;
begin
if ssLeft in shift then begin
case combobox1.ItemIndex of
1: begin Dugmemiz := TButton.Create (self); //yeni düğme oluşturuldu...
Dugmemiz.Parent:= self;
Dugmemiz.Caption:='Deneme - ' + IntToStr (butt);
Dugmemiz.Top:= y;
Dugmemiz.Left:= x;
Dugmemiz.Name:=TButton.ClassName+IntToStr (butt);
Dugmemiz.OnClick:=tiklama;
end;
2: begin Etiket := TLabel.Create (self); //yeni düğme oluşturuldu...
Etiket.Parent:= self;
Etiket.Caption:='Deneme - ' + IntToStr (labe);
Etiket.Top:= y;
Etiket.Left:= x;
Etiket.Name:=TLabel.ClassName+IntToStr (labe);
etiket.OnClick:=tiklama;
end;
3: begin Metin := TEdit.Create (self); //yeni düğme oluşturuldu...
Metin.Parent:= self;
Metin.text:='Deneme - ' + IntToStr (edit);
Metin.Top:= y;
Metin.Left:= x;
Metin.Name:=Tedit.ClassName+IntToStr (edit);
Metin.OnKeyPress:=tusbasimi;
Metin.OnEnter:= metne_giris;
Metin.OnExit:=metin_cikisi;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject); //Son nesneyi siler
begin
if Form1.ComponentCount > 11 then //temel nesneler dışındakiler silinebilir
begin
Components[Form1.ComponentCount-1].Free;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var i:integer;
Temp: TComponent;
begin
butt:=0;labe:=0;edit:=0;
for i:=0 to Form1.ComponentCount-1 do begin
Temp:=Components[i];
if Temp is TButton then inc(butt);
if Temp is TLabel then inc(labe);
if Temp is TEdit then inc(edit);
end;
label1.Caption:='Form üzerinde :'+#13+inttostr(butt)+' adet Button'
+#13+inttostr(labe)+' adet Label'+#13+inttostr(edit)+' adet Edit vardır'
+#13+inttostr(ComponentCount)+' Toplam Nesne';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex:=0;
Application.HintColor:=claqua;
Application.HintHidePause:=3000; //hint bekleme zamanı
Application.HintPause:=300; //hint çıkma zamanı
end;
procedure TForm1.FormKaydet1Click(Sender: TObject);
var dosya :TFileStream;i:integer;
begin
if SaveDialog1.Execute then
begin
// WriteComponentResFile(SaveDialog1.filename,Self); //*.dfm olarak da kayıt yapmak mümkün
dosya:=TFileStream.Create(SaveDialog1.FileName,fmOpenWrite or fmCreate);
for i:=11 to form1.ComponentCount-1 do
begin
dosya.WriteComponent(Components[i]);
end;
dosya.Free;
end;
end;
procedure TForm1.Yeni1Click(Sender: TObject);
var i,nesnesayisi:integer;
begin
if form1.ComponentCount>11 then
begin
nesnesayisi:=form1.ComponentCount-1;
for i:=nesnesayisi downto 11 do //ters yön olmazsa silinemez!...
Components[i].Free;
end;
end;
procedure TForm1.FormA1Click(Sender: TObject);
var dosya :TFileStream;nesne:TComponent;
dugmemiz:TButton;
etiket:TLabel;
metin:TEdit;
begin
if OpenDialog1.Execute then
begin
Yeni1Click(self);
dosya:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
while dosya.Position begin
nesne:=dosya.ReadComponent(nil);
InsertControl(nesne as Tcontrol); //sadece görünüm olarak varoluyor...?!
end;
dosya.Free;
end;
end;
procedure TForm1.Panel1Click(Sender: TObject);
var i:integer;nesneler:string;
begin
for i:=0 to form1.ComponentCount-1 do
nesneler:=nesneler+inttostr(i+1)+#9+Components[i].Name+' / '+Components[i].className+#13;
ShowMessage(nesneler);
end;
initialization
//formdaki tüm nesne tipleri
RegisterClasses ([TPanel, TCombobox, TLabel, TEdit, TButton]);
end.