Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: MoveStrings.dproj

Project Structure

MoveStrings.dpr
program MoveStrings;

uses
  Forms,
  MoveStrings_MainForm in 'MoveStrings_MainForm.pas' {FormMoveStrings};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TFormMoveStrings, FormMoveStrings);
  Application.Run;
end.
MoveStrings_MainForm.pas
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.
MoveStrings_MainForm.pas.dfm
object FormMoveStrings: TFormMoveStrings
  Left = 0
  Top = 0
  Caption = 'MoveStrings'
  ClientHeight = 292
  ClientWidth = 554
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 120
    Top = 8
    Width = 425
    Height = 273
    Lines.Strings = (
      'Memo1')
    TabOrder = 0
  end
  object btnMoveFailure: TButton
    Left = 8
    Top = 8
    Width = 97
    Height = 25
    Caption = 'btnMoveFailure'
    TabOrder = 1
    OnClick = btnMoveFailureClick
  end
  object btnRowByte: TButton
    Left = 8
    Top = 40
    Width = 97
    Height = 25
    Caption = 'btnRowByte'
    TabOrder = 2
    OnClick = btnRowByteClick
  end
end
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù