Classes, TP objects, records with methods... why not complicate the hell out of our programming habits? [...] I think the classes concept is clear enough to avoid any confusion and implementing more "exotic" stuff for the sake of compatibility
Note that a danger of using TP objects instead of records with methods is that TP objects are not safe with automated types (ansistrings, dynamic arrays). So I wouldn't recommend this.
QuoteNote that a danger of using TP objects instead of records with methods is that TP objects are not safe with automated types (ansistrings, dynamic arrays). So I wouldn't recommend this.Is that limitation documented? Never knew about it.
Neither did I. I ran on stackoverflow, and did execute the test I found there with FPC. Bug compatible.Jonas did own tests, and objects that are dynamically created (new(pobject) ) are safe according to him. (and indeed the test I found used objects statically)
I (and I think Zaher too) didn't mean "an object" (as in an instance of a class) but "the Object type" (as in "type TMyObj = Object ... end; "). It's probably not a recommended programming tool anymore, but it's closer to Delphi's "Record with methods" than classes, no?
Man, let's open up two new forum sections, one on algorithms and another one on data structures
In fact i meant the both Object and Classes the both way give us the needs from "Record with methods", so no need to add this feature for me, i am dreaming about managed objects.
Quote from: marcov on March 14, 2010, 10:15:36 pmNeither did I. I ran on stackoverflow, and did execute the test I found there with FPC. Bug compatible. Jonas did own tests, and objects that are dynamically created (new(pobject) ) are safe according to him. (and indeed the test I found used objects statically)Is there a bug report? or did Jonas say it wouldn't be fixed? I had another bug with objects, and that got fixed => so apparently objects seem to be still supported?
Neither did I. I ran on stackoverflow, and did execute the test I found there with FPC. Bug compatible. Jonas did own tests, and objects that are dynamically created (new(pobject) ) are safe according to him. (and indeed the test I found used objects statically)
type TRecWithMetods = object FValue: Integer; procedure Foo; end;Behaves exactly like a record. You do *NOT* need to care about freeing any memory. You do neither need to create it, nor destroy it.And what does "but only within the scope of one procedure" mean?The above can be used as a function result or var-parameter too.It can be a field in a class, or in *another* object.Of course like a record, they can not be circular. A record can not contain a field of it's own type. neither can an "object".
And what does "but only within the scope of one procedure" mean?The above can be used as a function result or var-parameter too.
Quote from: Martin_fr on March 14, 2010, 04:24:02 pmAnd what does "but only within the scope of one procedure" mean?The above can be used as a function result or var-parameter too.But such use cannot contain any dynamic types. Pointers or ansistrings/dyn arrays. The jury is still out if this is a feature or bug (see other parts in this thread), but Delphi does the same apparantly.
Records do not have inheritance. So it is to the best of my knowledge safe to use "type = object" as a record-with-methods.
type TParent = record a : integer; end; TChildA = record p : TParent; b : integer; end; TChildB = record p : TParent; c : Integer; end;...procedure ChangeParent(var p : TParent);...var c1: TChildA; c2: TChildB;ChangeParent(c1.p);ChangeParent(c2.p);