Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with System.MOVE

Posted on 2000-04-18
9
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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