Створення записної книжки

 

unit1.pas

 

procedure TForm1.Button1Click(Sender: TObject); //add

Var

 sect:String;

begin

 fn:=TIniFile.Create('data\contacts.ini');

 sect:=Edit1.Text;

 Fn.WriteString(sect,'tel_mob',Edit2.Text);

 Fn.WriteString(sect,'tel_dom',Edit3.Text);

 Fn.WriteString(sect,'tel_rab',Edit4.Text);

 Fn.WriteString(sect,'mail',Edit5.Text);

 Fn.WriteString(sect,'adress',Edit6.Text);

 Fn.WriteString(sect,'skype',Edit7.Text);

 Fn.WriteString(sect,'icq',Edit8.Text);

 Fn.WriteString(sect,'vk',Edit9.Text);

 Fn.WriteString(sect,'odnokl',Edit10.Text);

 fn.UpdateFile;

 fn.Destroy;

 hide;

 form4.Action2.Execute;

end;

 

procedure TForm1.Button2Click(Sender: TObject); // Cancel press

begin

 Hide;

end;

 

procedure TForm1.FormHide(Sender: TObject);

begin

 Form4.Enabled:=True;

end;

 

procedure TForm1.FormShow(Sender: TObject);

begin

 Form4.Enabled:=False;

end;

 

unit2.pas

 

procedure TForm2.Button1Click(Sender: TObject); //modify

Var

 c:TiniFile;

begin

 c:=TIniFile.Create('data\contacts.ini');

 c.EraseSection(sc);

 sc:=Edit1.Text;

 c.WriteString(sc,'tel_mob',Edit2.Text);

 c.WriteString(sc,'tel_dom',Edit3.Text);

 c.WriteString(sc,'tel_rab',Edit4.Text);

 c.WriteString(sc,'mail',Edit5.Text);

 c.WriteString(sc,'adress',Edit6.Text);

 c.WriteString(sc,'skype',Edit7.Text);

 c.WriteString(sc,'icq',Edit8.Text);

 c.WriteString(sc,'vk',Edit9.Text);

 c.WriteString(sc,'odnokl',Edit10.Text);

 c.UpdateFile;

 c.Destroy;

 hide;

 Form4.Action2Execute(self);

end;

 

procedure TForm2.Button2Click(Sender: TObject);

begin

 hide;

end;

 

procedure TForm2.FormHide(Sender: TObject);

begin

 Form4.Enabled:=True;

end;

 

procedure TForm2.FormShow(Sender: TObject); //auto name

begin

 Label1.Caption:=Form4.StringGrid1.Cells[0,0];

 Edit1.Text:=Form4.StringGrid1.Cells[1,0];

 Label2.Caption:=Form4.StringGrid1.Cells[0,1];

 Edit2.Text:=Form4.StringGrid1.Cells[1,1];

 Label3.Caption:=Form4.StringGrid1.Cells[0,2];

 Edit3.Text:=Form4.StringGrid1.Cells[1,2];

 Label4.Caption:=Form4.StringGrid1.Cells[0,3];

 Edit4.Text:=Form4.StringGrid1.Cells[1,3];

 Label5.Caption:=Form4.StringGrid1.Cells[0,4];

 Edit5.Text:=Form4.StringGrid1.Cells[1,4];

 Label6.Caption:=Form4.StringGrid1.Cells[0,5];

 Edit6.Text:=Form4.StringGrid1.Cells[1,5];

 Label7.Caption:=Form4.StringGrid1.Cells[0,6];

 Edit7.Text:=Form4.StringGrid1.Cells[1,6];

 Label8.Caption:=Form4.StringGrid1.Cells[0,7];

 Edit8.Text:=Form4.StringGrid1.Cells[1,7];

 Label9.Caption:=Form4.StringGrid1.Cells[0,8];

 Edit9.Text:=Form4.StringGrid1.Cells[1,8];

 Label10.Caption:=Form4.StringGrid1.Cells[0,9];

 Edit10.Text:=Form4.StringGrid1.Cells[1,9];

 sc:=Edit1.Text;

 Form4.Enabled:=False;

end;

 

Unit4.pas //main

 

procedure TForm4.Action1Execute(Sender: TObject); // add form call

begin

 Form1.Show;

end;

 

procedure TForm4.Action2Execute(Sender: TObject); //update

Var

 i:Integer;

begin

 ListBox1.Items.LoadFromFile('data\contacts.ini');

 i:=0;

while i<=ListBox1.Items.Count-1 do

 Begin

 if not ((Pos('[',ListBox1.Items[i])>0)and(Pos(']',ListBox1.Items[i])>0)) then

   ListBox1.Items.Delete(i)

  else

  Begin

   ListBox1.Items[i]:=Copy(ListBox1.Items[i],2,Length(ListBox1.Items[i])-2);

   i:=i+1;

  End;

 End;

end;

 

procedure TForm4.Action3Execute(Sender: TObject); //delete

begin

 f:=TIniFile.Create('data\contacts.ini');

 f.EraseSection(ListBox1.Items[ListBox1.ItemIndex]);

 f.UpdateFile;

 f.Destroy;

 Form4.Action2Execute(self);

end;

 

procedure TForm4.Action4Execute(Sender: TObject); //edit form call

begin

 Form2.Show;

end;

 

procedure TForm4.FormShow(Sender: TObject); //autofil string grid 0 column

begin

 Action2Execute(self);

 StringGrid1.RowCount:=10;

 StringGrid1.ColCount:=2;

 StringGrid1.ColWidths[0]:=200;

 StringGrid1.ColWidths[1]:=300;

 StringGrid1.Cells[0,0]:=Form1.Label1.Caption;

 StringGrid1.Cells[0,1]:=Form1.Label3.Caption;

 StringGrid1.Cells[0,2]:=Form1.Label4.Caption;

 StringGrid1.Cells[0,3]:=Form1.Label10.Caption;

 StringGrid1.Cells[0,4]:=Form1.Label5.Caption;

 StringGrid1.Cells[0,5]:=Form1.Label2.Caption;

 StringGrid1.Cells[0,6]:=Form1.Label6.Caption;

 StringGrid1.Cells[0,7]:=Form1.Label7.Caption;

 StringGrid1.Cells[0,8]:=Form1.Label8.Caption;

 StringGrid1.Cells[0,9]:=Form1.Label9.Caption;

end;

 

procedure TForm4.ListBox1Click(Sender: TObject); //single click left mouse button on List Box

Var

 sect:String;

begin

 sect:=ListBox1.Items[ListBox1.ItemIndex];

 F:=TIniFile.Create('data\contacts.ini');

 StringGrid1.Cells[1,0]:=sect;

 StringGrid1.Cells[1,1]:=F.ReadString(sect,'tel_mob','');

 StringGrid1.Cells[1,2]:=F.ReadString(sect,'tel_dom','');

 StringGrid1.Cells[1,3]:=F.ReadString(sect,'tel_rab','');

 StringGrid1.Cells[1,4]:=F.ReadString(sect,'mail','');

 StringGrid1.Cells[1,5]:=F.ReadString(sect,'adress','');

 StringGrid1.Cells[1,6]:=F.ReadString(sect,'skype','');

 StringGrid1.Cells[1,7]:=F.ReadString(sect,'icq','');

 StringGrid1.Cells[1,8]:=F.ReadString(sect,'vk','');

 StringGrid1.Cells[1,9]:=F.ReadString(sect,'odnokl','');

 F.UpdateFile;

 F.Destroy;

end;