Ver Mensaje Individual
  #11  
Antiguo 07-02-2013
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
ungrande87,

Cita:
Empezado por ungrande87
Estoy trabajando con Delphi 7 y quería saber como eliminar un renglón de un widestring.
Revisa este código:
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Elimina una palabra del texto de entrada.
function DeleteWord(Word : string; ListWord : WideString) : string;
var
   StrList : TStringList;
   i : Integer;
begin
   StrList := TStringList.Create;
   StrList.Text := ListWord;
   for i := StrList.Count-1 downto 0 do
      if StrList[i] = Word then
         StrList.Delete(i);
   Result := StrList.Text;
   StrList.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   AuxStr : WideString;
begin
   AuxStr := Memo1.Text;
   AuxStr := DeleteWord(Memo1.SelText,AuxStr);
   ShowMessage(AuxStr);
   Memo1.SelLength := 0;
end;

end.
El código anterior asigna el texto de un control TMemo a una variable de tipo WideString y por medio de la función DeleteWord elimina un texto seleccionado en la variable mencionada.

Nota: En la función DeleteWord la variable Word representa una línea del control TMemo formada por una o más palabras.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 07-02-2013 a las 02:37:16.
Responder Con Cita