Ecco la soluzione passatami da Goblin:
codice:
unit Email;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RzCmboBx, ExtCtrls;
type
TForm1 = class(TForm)
Lista: TRzComboBox;
Conta: TLabel;
GroupBox2: TGroupBox;
Label8: TLabel;
Server: TRzComboBox;
NomeServer: TLabel;
Pannello1: TPanel;
Contatto: TLabel;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ComboChange(Sender: TObject);
procedure ServerChange(Sender: TObject);
procedure ListaChange(Sender: TObject);
private
sPath: String;
Function Carica(oCombo: TRzComboBox; sFileName:String; Var oLista:TStringList): Integer;
public
oListaPublic: TStringList;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function TForm1.Carica(oCombo: TRzComboBox; sFileName:String; Var oLista:TStringList): Integer;
var I : Integer;
slConfig: TStringList;
begin
Result := -1;
slConfig := TStringList.Create;
Try
slConfig.LoadFromFile(sFileName);
For I := 0 to pred(slConfig.Count) do
oCombo.Items.Add(slConfig.Names[i]);
finally
oLista. Text := oLista. Text + slConfig.Text;
Result := slConfig.Count;
slConfig.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
oListaPublic := TStringList.Create;
sPath:= ExtractFilePath(Application.ExeName);
Conta.Caption := 'Ci Sono '+ IntToStr(Carica(Lista, sPath + '\Rubrica.Ini', oListaPublic)) + ' Contatti!';
Label1.Caption := 'Ci Sono '+ IntToStr(Carica(Server,sPath + '\Server.Ini', oListaPublic)) + ' Server!';
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
oListaPublic.Free;
end;
procedure TForm1.ComboChange(Sender: TObject);
begin
case (Sender as TRzComboBox).Tag of
1: NomeServer.Caption := oListaPublic.Values[(Sender as TRzComboBox).Text];
2: Contatto.Caption := oListaPublic.Values[(Sender as TRzComboBox).Text];
end;
end;
procedure TForm1.ServerChange(Sender: TObject);
begin
NomeServer.Caption := oListaPublic.Values[Server.Text];
end;
procedure TForm1.ListaChange(Sender: TObject);
begin
Contatto.Caption := oListaPublic.Values[Lista.Text];
end;
end.