Solved

Problem with System.MOVE

Posted on 2000-04-18
9
217 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
Independent Software Vendors: 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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