Ver Mensaje Individual
  #1  
Antiguo 01-05-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 23
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Mantixd,

Cita:
Empezado por Mantixd
...lo que quiero es que al hacer click en un botón me lea automáticamente todo el Memo1 y los datos encontrados (comparara el memo con el arreglo) los mande todos juntos al Memo2...
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;
    Memo2: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  RegAsm: Array[1..74] of string =  ('db','ALIGN','.ALPHA','ASSUME','.CODE','COMM','COMMENT',
                                     '.CONST','.CREF','.DATA','DB','DD','DF','DOSSEG','DQ',
                                     'DT','DW','ELSE','END','ENDIF','ENDM','ENDP','ENDS','EQU',
                                     '.ERRnn','EVEN','EXITM','EXTRN','.FARDATA','.FARDATA?',
                                     'GROUP','IF','IF1','IF2','IFB','IFDEF','IFDIF','IFE','IFIDN',
                                     'IFNB','IFNDEF','INCLUDE','INCLUDELIB','IRP','IRPC','LABEL',
                                     '.LALL','.LFCOND','.LIST','LOCAL','MACRO','.MODEL','NAME',
                                     'ORG','OUT','PAGE','PROC','PUBLIC','PURGE','.RADIX','RECORD',
                                     'REPT','.SALL','SEGMENT','.SEQ','.SFCOND','.STACK','STRUC',
                                     'SUBTTL','.TFCOND','TITLE','.XALL','.XCREF','.XLIST');

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Selecciona los Registros de Assembler de un TMemo con base en un Arreglo
procedure TForm1.Button1Click(Sender: TObject);
var
   SL: TStringList;
   i, j, k : Integer;
   Token : String;
   AuxStr : String;

begin

   SL := TStringList.Create;

   Memo2.Clear;

   for i := 0 to Memo1.Lines.Count - 1 do
   begin

      AuxStr := Memo1.Lines[i];

      for j := 1 to Length(AuxStr) do
      begin
         if (AuxStr[j] <> ' ') and (AuxStr[j] <> ',') then
            Token := Token + AuxStr[j]
         else
         begin
            SL.Add(Token);
            Token := EmptyStr;
         end
      end;

      SL.Add(Token);
      Token := EmptyStr;

      for j := 0 to SL.Count - 1 do
         for k := Low(RegAsm) to High(RegAsm) do
            if SL[j] = RegAsm[k] then
               Memo2.Lines.Add(Memo1.Lines[i]);

      SL.Clear;

   end;

   SL.Free;

end;

end.
El código anterior en Delphi 7 y Windows 7 Professional x32, analiza cada línea del TMemo1, las compara tipo Case Sensitive con un arreglo y si haya una ocurrencia copia dicha línea a TMemo2, siguiendo el mismo comportamiento sugerido en el ejemplo del Msg #4.

Espero sea útil

Nelson.
Responder Con Cita