Ver Mensaje Individual
  #12  
Antiguo 25-02-2012
Avatar de Delphius
[Delphius] Delphius is offline
Miembro Premium
 
Registrado: jul 2004
Ubicación: Salta, Argentina
Posts: 5.582
Reputación: 27
Delphius Va camino a la fama
Un ejemplo muy básico:

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  CHEMICALS_COUNT = 2;

type
  TChemical = record
    Name: string[20];
    Value: Double;
  end;

const
  CHEMICALS_LIST: array [0..CHEMICALS_COUNT - 1] of TChemical =
  (
    (Name: 'ele1'; Value: 0.1), // pos 0
    (Name: 'ele2'; Value: 0.2) // pos 1
  );

type
  TForm1 = class(TForm)
    cobx1: TComboBox;
    ll1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure cobx1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
 // llenamos el combo:
 for i := 0 to CHEMICALS_COUNT - 1 do
   cobx1.Items.Add(CHEMICALS_LIST[i].Name);
end;

procedure TForm1.cobx1Change(Sender: TObject);
var elem: string;
    value: Double;
begin
  elem := CHEMICALS_LIST[cobx1.ItemIndex].Name;
  value := CHEMICALS_LIST[cobx1.ItemIndex].Value;

  ll1.Caption := 'El valor del elemento ' + elem + ' es: ' + FloatToStr(value);
end;

end.

Saludos,
__________________
Delphius
[Guia de estilo][Buscar]
Responder Con Cita