Re: Delphi Strings an Memo

Posted by Jenny on November 15, 2005

In Reply to: Delphi Strings posted by Tsongkie on November 07, 2005

: hey, this is in my memo1:
: Poke 10abf 90 90 90
: Poke 10001 c2 b4 18
: how do i list it to my memo2 like this:
: bytes1 db 090h,090h,090h
: bytes2 db 0c2h,0b4h,018h
:
: Invoke PokeProc, offset WindCap, 10abfh, offset bytes1, 3 , NULL, NULL
: Invoke PokeProc, offset WindCap, 10001h, offset bytes2, 3 , NULL, NULL

Try this little Delphi procedure:

procedure TForm1.Memo1ToMemo2;
var
  i: integer;
  Line, S1, S2, S3, S4: string;
begin
  Memo2.Clear;
  // build first part of Memo2...
  for i := 0 to Memo1.Lines.Count - 1 do begin
    Line := Memo1.Lines[i]; // extract line from Memo1
    delete(Line, 1, 5); // remove 'Poke '
    S1 := Copy(Line, 1, Pos(' ', Line) - 1); // extract string 1
    delete(Line, 1, Pos(' ', Line));         // remove string 1 from line
    S2 := Copy(Line, 1, Pos(' ', Line) - 1); // string 2
    delete(Line, 1, Pos(' ', Line));         // remove string 2
    S3 := Copy(Line, 1, Pos(' ', Line) - 1); // string 3
    delete(Line, 1, Pos(' ', Line));         // remove string 3
    S4 := Copy(Line, 1, Pos(' ', Line) - 1); // string 4
    delete(Line, 1, Pos(' ', Line));         // remove string 4
    // add line to Memo2, built from string 1 to 4
    Memo2.Lines.Add('bytes' + IntToStr(i + 1) + ' db 0' +
      S1 + 'h,0' + S2 + + 'h,0' + S3 + 'h,0' + S4 + 'h');
  end;
  Memo2.Lines.Add(''); // add empty line
  // build second part of Memo2...
  for i := 0 to Memo1.Lines.Count - 1 do 
    Memo2.Lines.Add('Invoke PokeProc, offset WindCap, ' + 
      S1 + 'h, offset bytes' + IntToStr(i + 1) + '3 , NULL, NULL');
end;

Good luck,
Jenny

Related Articles and Replies


Delphi Programming Forum