Ver Mensaje Individual
  #1  
Antiguo 11-09-2011
Nicolas_2011 Nicolas_2011 is offline
Miembro
NULL
 
Registrado: sep 2011
Posts: 59
Reputación: 15
Nicolas_2011 Va por buen camino
conversion de sistema de numeracion + delphi 7

gente necesito ayuda, tengo todo el codigo, pero no puedo lograr unirlo en un solo radiogroup aca le va el codigo. lo que esta en azul supuestamente esta bien pero lo de rojo es el problema que tengo..espero q entiendan mi pequeño inconveniente de no ser asi explico mejor, espero su ayuda!!!
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    e: TEdit;
    rgbase: TRadioGroup;
    procedure eKeyPress(Sender: TObject; var Key: Char);
    procedure rgbaseClick(Sender: TObject);
  private
    Function dr (s:string; bl:integer):string; //base llegada
    Function sp (s:string ;bp:integer):string; // base partida
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
 Function TForm1.sp (s:string ;bp:integer):string; // suma ponderada
 var
  i:integer;
  m:Extended;
  Begin
  m:=0;
    For i:=1 to Length(s) do
      Case s[i] Of
        'A' : m:= m + 10* Power(bp,Length(s) - i);
        'B' : m:= m + 11* Power(bp,Length(s) - i);
        'C' : m:= m + 12* Power(bp,Length(s) - i);
        'D' : m:= m + 13* Power(bp,Length(s) - i);
        'E' : m:= m + 14* Power(bp,Length(s) - i);
        'F' : m:= m + 15* Power(bp,Length(s) - i);
          Else
            m:= m + StrToInt(s[i])*Power(bp,Length(s)-i);
            end;
    result:=FloatToStr(m);
end;
 Function TForm1.dr (s:string; bl:integer):string; // division reiterada
  Var
  num: integer;
  d:integer;
  resultado:string;
        Begin
        num:=StrToInt(s);
        resultado:=  ' ';
        while (num > 0) do
          begin
            d:= num mod bl;
            num:= num div bl;
                     case d of
              10: resultado:= 'A' + resultado;
              11: resultado:= 'B' + resultado;
              12: resultado:= 'C' + resultado;
              13: resultado:= 'D' + resultado;
              14: resultado:= 'E' + resultado;
              15: resultado:= 'F' + resultado;
                else
                  resultado:= IntToStr(d) + resultado;
              end;
              end;
              Result:=resultado;
            end;
{$R *.dfm}

procedure TForm1.eKeyPress(Sender: TObject; var Key: Char);   // restricciones
begin
  Case RgBase.ItemIndex Of
    0:Begin
    If not (Key in ['1','0', #8]) then
      key:= #0
end;
    1:Begin
    If not (Key in ['0'..'7', #8]) then
      key:= #0
end;
    2:Begin
    If not (Key in ['0'..'9', #8]) then
      key:= #0
end;
    3:Begin
    If not (Key in ['A'..'F', '0'..'9', #8]) then
      key:= #0
end;
end;

end;

procedure TForm1.rgbaseClick(Sender: TObject);  // conversion
begin
e.Enabled := true;
e.SetFocus;
 { ¡¡ AQUI EL PROBLEMA !! }
 Begin
  If rgbase.ItemIndex <> 2 then
    case rgbase.ItemIndex of
       0: e.Text := dr(e.Text,2);
       1: e.Text := dr(e.Text,8);
       2: e.Text := dr(e.Text,10);
       3: e.Text := dr(e.Text,16)
       Else
begin
If rgbase.ItemIndex = 2 then
  case rgbase.ItemIndex of
  0 : e.Text := sp(e.Text,2);
  1 : e.Text:= sp(e.Text,8);
  2 : e.Text:= sp(e.Text,10);
  3 : e.text:= sp(e.Text,16);
end;

end;


end;
end;
end;
end.
la idea es que seleccione un item y recien se habilite el edit cuando ingresa un numero hace click en otro item y cambia automaticamente el valor y asi sucesivamente.

Última edición por ecfisa fecha: 11-09-2011 a las 01:57:29. Razón: ETIQUETAS [DELPHI] [/DELPHI]
Responder Con Cita