Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Generar Codigo Por Letras Segun Criterio (https://www.clubdelphi.com/foros/showthread.php?t=71638)

Lenny 30-12-2010 21:18:50

Generar Codigo Por Letras Segun Criterio
 
De antemano muchas por cualquier ayuda...

Necesito generar un CODIGO a partir de los 2 ó 3 primeros caracteres de un producto, como por ejemplo:

COCA COLA/LIGHT /BOTELLA/PLASTICA / Lts / 2.5 = COCLIBOTPLALT2.5
COCA COLA/NORMAL/BOTELLA/VIDRIO / Lts / 1.0 = COCNORBOVIDLT1.0
FANTA / NORMAL/LATA / LATA / Cc / 350 = FANNOLATLATCC350

por mas que doy vueltas no encuentro como hacer que el programa, al ingresar los criterios genere ese codigo automaticamente....
se entiende??? ante cualquier pregunta adicional estare atento, muchas gracias de antemano

PD: Utilizo DELPHI 2010, ZEOS, MYSQL

cloayza 30-12-2010 22:32:31

A la rapida escribi este codigo, prueba y me cuentas...

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);

   Function GetCodigo(AText:String; ASep:Char):string;
   var
      j:Integer;
      List:TStrings;
   begin
        List:=TStringList.Create;

        List.Clear;
        List.Delimiter    :=ASep;
        List.DelimitedText:=ReplaceStr( AText,' ','');

        Result:='';

        for j := 0 to List.Count - 1 do
        begin
            if Length(List[j])<3 then
               Result:=Result+List[j]
            else
                Result:=Result+Copy(List[j],1,3);
        end;
        Result:=UpperCase(Result);
        List.Free;
   end;

begin
     ShowMessage( GetCodigo('COCA COLA/LIGHT /BOTELLA/PLASTICA / Lts / 2.5', '/') );
end;

Saludos cordiales

Aleca 30-12-2010 22:57:28

Fijate si te sirve algo asi.
Código Delphi [-]
procedure TForm1.SButtonClick(Sender: TObject);
var
  cTxt, cClave, cParcial: String;
  nPos, i: Integer;
  aCant: Array[0..5] of Integer;
begin
  aCant[0] := 3;
  aCant[1] := 2;
  aCant[2] := 3;
  aCant[3] := 3;
  aCant[4] := 2;
  aCant[5] := 3;
  i := 0;
  cTxt := 'COCA COLA/LIGHT /BOTELLA/PLASTICA / Lts / 2.5';
  cClave := '';
  while Length(cTxt) > 0 do
  begin
    nPos := Pos('/', cTxt);
    if nPos = 0 then //Por la ultima parte.
    begin
      nPos := Length(cTxt);
      cParcial := Copy(cTxt, 0, nPos);
    end
    else
      cParcial := Copy(cTxt, 0, nPos - 1);
    cClave := cClave + Copy(Trim(cParcial), 0, aCant[i]);
    cTxt := Copy(cTxt, nPos + 1, Length(cTxt) - nPos);
    inc(i);
  end;
  cClave := UpperCase(cClave);
  SButton.Caption := cClave;
end;

ecfisa 30-12-2010 23:10:22

Hola.

Un modo que se me ocurre es:

Código Delphi [-]
{ ADataSet: datos (registro actual) - NCar: cantidad de caracteres por campo }
function NuevoCodigo(ADataSet: TDataSet; NCar: Byte): string;
var
  i: integer;
begin
  Result:= '';
  for i:= 0 to ADAtaSet.FieldCount - 1 do
    Result:= Result + Copy(ADataSet.Fields[i].AsString, 1, NCar);
end;

Llamada:
Código Delphi [-]
...
var
  NewCod: string;
begin
  NewCod:= NuevoCodigo(DataSet, 2);
end.


Saludos.

Lenny 31-12-2010 01:43:35

Hoooooo!!! Se pasaron!!! mil gracias, lo reviso y les cuento como me fue!!! mil gracias nuevamente por la ayuda!!!

Lenny 31-12-2010 03:29:18

GRACIAS A TODOS..... ECFISA!!! es justamente lo que necesitava, quedo increible gracias!!!


La franja horaria es GMT +2. Ahora son las 15:29:56.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi