unit GestoreForm;
{Sorgente per Lazarus}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CheckLst,
Nominativo,IoFile;
type
TForm1 = class(TForm)
CheckListBoxSiti: TCheckListBox;
LabelEtichettaSiti: TLabel;
LabeledEditNome: TLabeledEdit;
LabeledEditURL: TLabeledEdit;
LabeledEditUtente: TLabeledEdit;
LabeledEditPass: TLabeledEdit;
MemoNote: TMemo;
LabelNoteEventuali: TLabel;
ButtonCarica: TButton;
ButtonCancellaSelezionati: TButton;
LabelCaratteriDigitati: TLabel;
ButtonLibera: TButton;
ButtonModifica: TButton;
procedure FormCreate(Sender: TObject);
procedure ButtonCaricaClick(Sender: TObject);
procedure LabeledEditNomeChange(Sender: TObject);
procedure LabeledEditURLChange(Sender: TObject);
procedure MemoNoteChange(Sender: TObject);
procedure ButtonCancellaSelezionatiClick(Sender: TObject);
procedure CheckListBoxSitiClick(Sender: TObject);
procedure ButtonLiberaClick(Sender: TObject);
procedure LabeledEditPassChange(Sender: TObject);
procedure LabeledEditUtenteChange(Sender: TObject);
procedure ButtonModificaClick(Sender: TObject);
procedure LabeledEditNomeDblClick(Sender: TObject);
procedure LabeledEditURLDblClick(Sender: TObject);
procedure LabeledEditUtenteDblClick(Sender: TObject);
procedure LabeledEditPassDblClick(Sender: TObject);
private
{ Déclarations privées }
procedure cancella;
procedure edita_Indirizzi;
function giaEsistente(esaminato:indirizzo):Boolean;
procedure aggiungiRecord(nuovo:indirizzo; posizione:Longint);
public
{ Déclarations publiques }
registro:string;
fileLogico:fiolima;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
registro:=GetCartella+'\dati.dat';
edita_Indirizzi;
form1.Caption:='Indirizzi';
end;
procedure TForm1.cancella;
begin
LabeledEditNome.Text:='';
LabeledEditURL.Text:='';
LabeledEditUtente.Text:='';
LabeledEditPass.Text:='';
MemoNote.Lines.Clear;
CheckListBoxSiti.Items.Clear;
LabelCaratteriDigitati.Caption:='';
end;
procedure TForm1.ButtonCaricaClick(Sender: TObject);
var nuovo:indirizzo;
i:integer;
begin
nuovo:=indirizzoNullo;
nuovo.nome:=LabeledEditNome.Text;
nuovo.indirizzo:=LabeledEditURL.Text;
nuovo.utente:=LabeledEditUtente.Text;
nuovo.pas:=LabeledEditPass.Text;
i:=0;
while i<MemoNote.Lines.Count do
begin
nuovo.note:=nuovo.note + MemoNote.Lines[i];
i:=i+1;
if i<MemoNote.Lines.Count then nuovo.note:=nuovo.note+#13+#10;
end;
if (not giaEsistente(nuovo)) and (not ugualeANullo(nuovo)) then
begin
aggiungiRecord(nuovo, -5);
end;
end;
procedure TForm1.LabeledEditNomeChange(Sender: TObject);
begin
LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditNome.Text));
end;
procedure TForm1.LabeledEditURLChange(Sender: TObject);
begin
LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditURL.Text));
end;
procedure TForm1.MemoNoteChange(Sender: TObject);
var somma,linee:integer;
begin
somma:=0;
linee:=0;
while linee<MemoNote.Lines.Count do
begin
somma:=somma+length(MemoNote.Lines[linee]);
linee:=linee+1;
end;
LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(somma)+' su '+IntToStr(linee)+' linee';
end;
procedure TForm1.ButtonCancellaSelezionatiClick(Sender: TObject);
var i,j,fine,selezione:longint;
copia:fiolima;
elemento:indirizzo;
percorsoCopia,breveTesto:string;
begin
percorsoCopia:=getCartella+'\copia.cop';
selezione:=-500;
if (filelogico.ApriFile(registro, 'a')) and (copia.ApriFile(percorsoCopia, 'w')) then
begin
fine:=CheckListBoxSiti.Items.Count;
i:=0;
j:=0;
while i<fine do
begin
elemento:=filelogico.leggi(i);
if not CheckListBoxSiti.Checked[i] then
begin
copia.scrivi(elemento, j);
j:=j+1;
end
else
begin
breveTesto:='Cancello'+#13+#10+elemento.nome+char(13)+char(10)+elemento.indirizzo;
// if selezione <>mrYesToAll then selezione:=MessageDlg(breveTesto, mtConfirmation, mbYesAllNoAllCancel, 0); Istruzione per Delphi
if selezione <>mrYesToAll then selezione:=MessageDlg('Cosa fare ?', breveTesto, mtConfirmation, [mbYes, mbNo, mbIgnore],0 ); // Nuova istruzione riscritta per Lazarus
if not((selezione=mrYesToAll) or (selezione=mrYes)) then
begin
copia.scrivi(elemento, j);
j:=j+1;
end;
end;
i:=i+1;
end;
filelogico.ChiudiFile;
copia.ChiudiFile;
DeleteFile(registro);
RenameFile(percorsoCopia, registro);
edita_Indirizzi;
LabeledEditNome.SetFocus;
end
else
ShowMessage('Fine '+fileLogico.GetNome+' non trovato!');
end;
procedure TForm1.edita_Indirizzi;
var elemento:indirizzo;
begin
cancella;
if fileLogico.ApriFile(registro, 'r') then
begin
while not fileLogico.FineFile do
begin
elemento:=fileLogico.leggi;
CheckListBoxSiti.Items.Add(elemento.nome);
end;
LabelEtichettaSiti.Caption:='Siti presenti: '+IntToStr(fileLogico.NumeroDiCampi);
fileLogico.ChiudiFile;
end
else
ShowMessage('Il file '+fileLogico.GetNome+char(13)+char(10)+'non è presente !');
end;
procedure TForm1.CheckListBoxSitiClick(Sender: TObject);
var elemento:indirizzo;
selezione:longint;
begin
selezione:=CheckListBoxSiti.ItemIndex;
if selezione>=0 then
if fileLogico.ApriFile(registro, 'r') then
begin
elemento:=fileLogico.leggi(selezione);
LabeledEditNome.Text:=elemento.nome;
LabeledEditURL.Text:=elemento.indirizzo;
LabeledEditUtente.Text:=elemento.utente;
LabeledEditPass.Text:=elemento.pas;
MemoNote.Lines.Clear;
MemoNote.Lines.Add(elemento.note);
fileLogico.ChiudiFile;
end;
end;
procedure TForm1.ButtonLiberaClick(Sender: TObject);
begin
edita_Indirizzi;
LabeledEditNome.SetFocus;
end;
procedure TForm1.LabeledEditPassChange(Sender: TObject);
begin
LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditPass.Text));
end;
procedure TForm1.LabeledEditUtenteChange(Sender: TObject);
begin
LabelCaratteriDigitati.Caption:='Caratteri: '+IntToStr(length(LabeledEditUtente.Text));
end;
function TForm1.giaEsistente(esaminato:indirizzo):Boolean;
var risultato:Boolean;
letto:indirizzo;
begin
risultato:=False;
if fileLogico.ApriFile(registro, 'r') then
begin
while (not risultato) and (not fileLogico.FineFile) do
begin
letto:=fileLogico.leggi();
risultato:=recordUguali(letto, esaminato);
end;
fileLogico.ChiudiFile;
end;
giaEsistente:=risultato;
end;
procedure TForm1.aggiungiRecord(nuovo:indirizzo; posizione:Longint);
begin
if fileLogico.ApriFile(registro, 'a') then
begin
if posizione>=0 then
begin
fileLogico.scrivi(nuovo, posizione);
end
else
begin
fileLogico.scrivi(nuovo);
end;
fileLogico.ChiudiFile;
end
else
begin
MessageDlg('Ipoossibile aprire il file '+fileLogico.GetNome, mtError, mbOKCancel, 0);
Application.Terminate;
end;
edita_Indirizzi;
LabeledEditNome.SetFocus;
end;
procedure TForm1.ButtonModificaClick(Sender: TObject);
var daModificare:indirizzo;
linee,selezione:integer;
begin
daModificare:=indirizzoNullo;
if CheckListBoxSiti.ItemIndex>=0 then
begin
daModificare.nome:=LabeledEditNome.Text;
daModificare.indirizzo:=LabeledEditURL.Text;
daModificare.utente:=LabeledEditUtente.Text;
daModificare.pas:=LabeledEditPass.Text;
linee:=0;
while linee<MemoNote.Lines.Count do
begin
daModificare.note:=daModificare.note+MemoNote.Lines[linee];
linee:=linee+1;
if linee<MemoNote.Lines.Count then daModificare.note:=daModificare.note+#13+#10;
end;
selezione:=MessageDlg('Modifica in'+#13+#10+daModificare.nome+#13+#10+daModificare.indirizzo , mtConfirmation, mbYesNoCancel, 0);
if (not ugualeANullo(daModificare)) and (selezione=mrYes) then
aggiungiRecord(daModificare, CheckListBoxSiti.ItemIndex);
end;
edita_Indirizzi;
LabeledEditNome.SetFocus;
end;
procedure TForm1.LabeledEditNomeDblClick(Sender: TObject);
begin
LabeledEditNome.SelStart:=0;
LabeledEditNome.SelLength:=length(LabeledEditNome.Text);
end;
procedure TForm1.LabeledEditURLDblClick(Sender: TObject);
begin
LabeledEditURL.SelStart:=0;
LabeledEditURL.SelLength:=length(LabeledEditURL.Text);
end;
procedure TForm1.LabeledEditUtenteDblClick(Sender: TObject);
begin
LabeledEditUtente.SelStart:=0;
LabeledEditUtente.SelLength:=length(LabeledEditUtente.Text);
end;
procedure TForm1.LabeledEditPassDblClick(Sender: TObject);
begin
LabeledEditPass.SelStart:=0;
LabeledEditPass.SelLength:=length(LabeledEditPass.Text);
end;
end.