Solved

Problem with System.MOVE

Posted on 2000-04-18
9
210 Views
Last Modified: 2010-04-04
I have a problem with function MOVE from System.pas :o(

Here sample of my project for Delphi4.

If you will press BitBtn1, you will see
a result of execution function MOVE().

Memo1 not equal Memo2 :o(
Where is the problem?

---------------cut---------------
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  R,D   : PChar;
  Length: integer;

implementation

{$R *.DFM}

procedure TForm1.BitBtn1Click(Sender: TObject);

begin
  Length := System.Length(Memo1.Lines.Text);
  GetMem(D, Length);
  R := Memo1.Lines.GetText;
  System.Move( R^, D^, Length);
  Memo2.Lines.Text := string(D);
  FreeMem(D);
end;

end.
---------------cut---------------
object Form1: TForm1
  Left = 106
  Top = 115
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 144
    Top = 32
    Width = 425
    Height = 105
    Lines.Strings = (
      '123456')
    TabOrder = 0
  end
  object Memo2: TMemo
    Left = 144
    Top = 152
    Width = 425
    Height = 145
    TabOrder = 1
  end
  object BitBtn1: TBitBtn
    Left = 48
    Top = 40
    Width = 75
    Height = 25
    Caption = 'BitBtn1'
    TabOrder = 2
    OnClick = BitBtn1Click
  end
end

---------------cut---------------
0
Comment
Question by:DValery
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 2727260
Why are you doing it like that?

What's wrong with...

    Memo2.Lines:=Memo1.Lines;

John.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2727300
Use this:

var length: Cardinal;
  R,D   : PChar;
begin
  R := Memo1.Lines.GetText;
  Length := strlen(R) + 1;
  GetMem(D, Length);
  System.Move(R^, D^, Length);
//  StrCopy(D, R);  can be used too
  Memo2.Lines.Text := string(D);
  FreeMem(D);
end;


I tested it and it seems to work  :o)

Regards,

Epsylon.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2727301
John, I think it is just for testing the move function...
0
 
LVL 1

Author Comment

by:DValery
ID: 2729285
It's only example that is sowing problem.
I'm using MOVE() for copy blocks of data (not string). Block data source not equal block data destination :o(

If you will make break point on string: "Memo2.Lines.Text := string(D);"
then you will can see the result execution MOVE() in R & D pointers.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Expert Comment

by:shenqw
ID: 2729520
Your code works fine on d5+pack1
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2729566
??????

What's wrong with it????
0
 
LVL 1

Author Comment

by:DValery
ID: 2729653
I try it on d5+pack1 and here result:
R:
"123456
"
D:
"'123456
,>¼'"
0
 
LVL 3

Accepted Solution

by:
shenqw earned 100 total points
ID: 2729927
yes ,i got it.

i think you must do like follow:

  Length := System.Length(Memo1.Lines.Text);
  GetMem(D, Length+1);
  R := Memo1.Lines.GetText;
  ZeroMemory(D,Length+1);
  System.Move( R^, D^, Length);
  Memo2.Lines.Text := string(D);
  FreeMem(D);

//string(D); Convert PChar to string,It only end when meet #0.

0
 
LVL 1

Author Comment

by:DValery
ID: 2729964
Thanks shenqw!
I saw my error ;o)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now