Ver Mensaje Individual
  #5  
Antiguo 03-08-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola NeoNew.

Cuando agregaste "Cuento con una tabla de convenciones...", me quedé pensando que quizá sea muy larga la lista de abreviaturas y del modo anterior te resultaría un poco tedioso...

Si ya tenes una tabla creada, podrías hacer:
Código Delphi [-]
...
implementation  

// (también podrías declararlas como privadas)
var
  FPalabra: TStrings;
  FAbrev: TStrings;

// Abrir tabla de abreviaturas y cargar 
procedure TForm1.FormCreate(Sender: TObject);
begin
  FPalabra:= TStringList.Create;
  FAbrev:= TStringList.Create;
  with tbAbreviaturas do
  begin
    Open;
    while not eof do
    begin
      FPalabra.Add(FieldByName('Palabra').AsString);
      FAbrev.Add(FieldByName('Abreviat').AsString);
      Next;
    end;
    Close;
  end;
end;

// Obtener abreviaturas
function TForm1.Abreviar(const Texto: string): string;
var
  i,ix: Integer;
begin
  Result:= Texto;
  with TStringList.Create do
  try
    Delimiter:= ' ';
    DelimitedText:= Texto;
    for i:= 0 to Count-1 do
    begin
      ix:= FPalabra.IndexOf(Strings[i]);
      if ix <>-1 then
        Result:= StringReplace(Result, Strings[i],FAbrev[ix],[]);
    end;
  finally
    Free;
  end;
end;

// Ejemplo de llamada
procedure TForm1.Button1Click(Sender: TObject);
begin
  Label2.Caption:= Abreviar(Label1.Caption)
end;

...

// Liberar
procedure TForm1.FormDestroy(Sender: TObject);
begin
  if Assigned(FPalabra) then
    FPalabra.Free;
  if Assigned(FAbrev) then
    FAbrev.Free;
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita