Solved

Problem with System.MOVE

Posted on 2000-04-18
9
213 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now