movestrings_mainform.pas

来自「source code for the Marco Cantu s book D」· PAS 代码 · 共 67 行

PAS
67
字号
unit MoveStrings_MainForm;

interface

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

type
  TFormMoveStrings = class(TForm)
    Memo1: TMemo;
    btnMoveFailure: TButton;
    btnRowByte: TButton;
    procedure btnMoveFailureClick(Sender: TObject);
    procedure btnRowByteClick(Sender: TObject);
  private
    procedure Log (const strMsg: string);
  public
    { Public declarations }
  end;

var
  FormMoveStrings: TFormMoveStrings;

implementation

{$R *.dfm}

procedure TFormMoveStrings.btnMoveFailureClick(Sender: TObject);
var
  str1, str2: string;
  buffer: TBytes;
begin
  str1 := 'Hello world';

  SetLength (buffer, Length (str1));
  Move (str1[1], buffer[1], Length (str1));

  SetLength (str2, Length (buffer));
  Move (buffer[1], str2[1], Length (buffer));

  Log (str1 + ' becomes ' + str2);
end;

procedure TFormMoveStrings.btnRowByteClick(Sender: TObject);
var
  str1, str2: RawByteString;
  buffer: TBytes;
begin
  str1 := 'Hello world';

  SetLength (buffer, Length (str1));
  Move (str1[1], buffer[1], Length (str1));

  SetLength (str2, Length (buffer));
  Move (buffer[1], str2[1], Length (buffer));

  Log (str1 + ' becomes ' + str2);
end;

procedure TFormMoveStrings.Log(const strMsg: string);
begin
  Memo1.Lines.Add (strMsg);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?