-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about Assign chapter #4
Comments
I didn't place that sentence ("Be careful when calling inherited...") in a proper context. These are good questions, and I will update the documentation to answer them. Te key is to know how the My intention was to say this:
To understand the need when to call (or not to call) "inherited" from the Assign implementation, and how it relates to the AssignTo method, it's best to look at the TPersistent.Assign and TPersistent.AssignTo implementations:
(This is not the exact source code, I simplified it to hide the boring details abuot how the exception message is build. The exact source code, in the FPC standard library, can be found in the So, if neither Assign nor AssignTo are overridden, then calling them will result in an exception. Also, note that there is no code in TPersistent implementation that automatically copies all the fields (or all the published fields) -- you need to do that yourself. You can use RTTI for that, but for simple cases you will probably just list the fields to be copied manually.
When you have a class like Assuming that you implemented
|
I improved that section, roughly based on my own comment above. You can read it online, at the standard location:
The commit is 5b5cdf0 . |
Thanks a lot! Now it's all clear! :) |
Hi, Michalis!
I've got a problem understanding the following line:
Could you please explain it more specificly...
What's bad about using inherited
Assign
method? It doesn't copy all the fields? Or only those published?What are the cases when one cannot handle the assignment in his code? Looks quiet straightforward to me... Of course, something more automatic (that won't require me to keep in mind to add each new field to Assign method) would be better, but anyway?
What "this" exactly allows
AssignTo
method to work - TPersistent.Assign or manual Assign implementation?What sort of exception is risen? Or is it just a possibility to raise a manual exception in case the assignment cannot be done (by using some manual internal checks)?
Sorry for, maybe, very stupid question :) I've never used Assign before, so this might be something very basic...
Actually I don't really need exact answers to these questions (I'm almost sure, I'll figure it out, when I'll make something like this in practice), but the fact that I don't understand them makes me unsure whether I've translated those sentences correctly :)
The text was updated successfully, but these errors were encountered: