Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Rubrica (Delphi 7)

    con un codice riuscivo a visualizzare in un label un nominativo associato ad un server, ad esempio mail.libero.it=infostrada, mail.libero.it compariva in un Tedit e infostrada in un label. Adesso questo codice l'ho modificato per ottenere lo stesso risultato anche per una rubrica ma non vuole funzionare. Posto il codice:
    codice:
    unit Email;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, RzPanel, StdCtrls, Buttons, Mask, ToolWin,
      TLHelp32, Printers,
      ComCtrls, ScktComp,
      XPStyleActnCtrls, ActnList, ActnMan, Menus, RzDlgBtn, jpeg, StdActns, ExtActns,
      RzButton, WinTypes, ShellAPI, mmSystem, Sockets, WinInet, RzShellDialogs,
      RzRadGrp, RzEdit, RzStatus, Registry, RzLabel, RzDBLbl,
      RzRadChk, StrUtils, RzCmboBx, RzSpnEdt;
    
    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 ServerChangeClik(Sender: TObject);
        procedure RubricaChangeClik(Sender: TObject);
        procedure CaricaClick(Sender: TObject);
    
      private
    
      public
        { Public declarations }
        end;
    
    var
      Form1: TForm1;
      slConfig: TStrings;
    const
      CurrentState : byte = 1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    //Carica i contatti
      CaricaClick(Sender);
          end;
    
    //Info Lista Server
    procedure TForm1.ServerChangeClik(Sender: TObject);
    begin
     NomeServer.Caption := slConfig.Values[Server.Text];
    end;
    
    //Info Lista Rubrica
    procedure TForm1.RubricaChangeClik(Sender: TObject);
    begin
     Contatto.Caption := slConfig.Values[Lista.Text];
    end;
    
    procedure TForm1.CaricaClick(Sender: TObject);
    var
    CLines, I : Integer;
    begin
      slConfig := TStringList.Create;
      slConfig.LoadFromFile('Rubrica.ini');
    for I := 0 to pred(slConfig.Count) do Lista.Items.Add(slConfig.Names[i]);
      slConfig.LoadFromFile('Server.ini');
    for I := 0 to pred(slConfig.Count) do Server.Items.Add(slConfig.Names[i]);
      CLines := 0;
    for I := 0 to  Lista.Items.Count - 1 do
    begin
      CLines := CLines + 1;
    end;
      Conta.Caption := 'Ci Sono '+ IntToStr(CLines) + ' Contatti!';
      CLines := 0;
    for I := 0 to  Server.Items.Count - 1 do
    begin
      CLines := CLines + 1;
    end;
      Label1.Caption := 'Ci Sono '+ IntToStr(CLines) + ' Server!';
    end;
    
    end.
    Come posso procedere?

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472
    Originariamente inviato da camaleonteplus
    Adesso questo codice l'ho modificato per ottenere lo stesso risultato anche per una rubrica ma non vuole funzionare.
    "Non vuole funzionare" non significa nulla e non da alcuna indicazione del problema che riscontri.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Ho fatto in questo modo:
    Codice sorgente - presumibilmente Delphi

    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 ServerChangeClik(Sender: TObject);
    procedure RubricaChangeClik(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ComboChange(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: TComboBox; 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 TcomboBox).Tag of
    1: NomeServer.Caption := oListaPublic.Values[(Sender as TcomboBox).Text];
    2: Contatto.Caption := oListaPublic.Values[(Sender as TcomboBox).Text];
    end;
    end;

    end.


    Mi da questo errore:
    [Error] Email.pas(42): Declaration of 'Carica' differs from previous declaration
    in questa riga:
    Codice sorgente - presumibilmente Delphi

    Function TForm1.Carica(oCombo: TComboBox; sFileName:String; Var oLista:TStringList): Integer;


    Perchè:-? e come posso risolvere:-?

  4. #4
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472
    Originariamente inviato da camaleonteplus
    [Error] Email.pas(42): Declaration of 'Carica' differs from previous declaration
    in questa riga
    Sarebbe sufficiente tradurre dall'inglese per capire qual è l'errore, o fare una ricerca su Google.

    L'errore è così banale - anche per chi conosce appena il linguaggio - che non voglio nemmeno sforzarmi di dare la soluzione.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  5. #5
    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.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.