Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

what is wrong with this..(trying to use assign)

Posted on 2005-05-09
6
Medium Priority
?
194 Views
Last Modified: 2012-05-05
i have this class..

type
  test = class(tpersistent)
  private
    Fp: string;
    procedure Setp(const Value: string);
  public
  property p : string read Fp write Setp;
end;

and i want to use like this

procedure TForm1.Button1Click(Sender: TObject);
var
  a, b : test;
begin
  a := test.Create;
  a.p := 'something'
  b := test.Create;

  b.Assign(a);
  showmessage(b.p);
end;

and i recevive un error message cannot assign test to test...what is wrong?..
0
Comment
Question by:ThoseBug
  • 2
4 Comments
 
LVL 3

Expert Comment

by:jpedef
ID: 13958466
Take a look to TPersistent's source.
You find that you must manually override either Assign or AssignTo procedure.
0
 
LVL 3

Author Comment

by:ThoseBug
ID: 13958583
sorry...can you be more specific..?..a line of code may be..?
0
 
LVL 3

Accepted Solution

by:
jpedef earned 200 total points
ID: 13958670
Example code:

type
  test = class(tpersistent)
  private
    Fp: string;
    procedure Setp(const Value: string);
  protected
    procedure AssignTo(Dest: TPersistent); override;
  public
  property p : string read Fp write Setp;
end;

...
procedure test.AssignTo(Dest: TPersistent);
begin
  if Dest is test then
    (Dest as test).Setp(Fp)
  else
    inherited; //** Raises an EConvertError
end;
0
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 200 total points
ID: 13959238
If you wrote the assign as above, you would still have to write the physical code for each of the properties of the object - which basically defeats the the idea of an assign.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses

810 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