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
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
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.