Results 1 to 5 of 5

Thread: Calling other constructor ok?

  1. #1

    Calling other constructor ok?

    Assume i have class A (fictional code)
    Code:
    type
      TClassA = class
      public
        constructor Create(width, height: integer);
        constructor Create;
        // Seems to compile fine without adding word "overload"
      end;
    
    implementation
    
    constructor TClassA.Create(width, height: integer);
    begin
      DoSomething(width, height);
    end;
    
    constructor TClassA.Create;
    begin
      Create(100, 100);
      // Now what happens here? Am i creating an object that will not get
      // assigned to any variable, basically a memory leak?
    end;
    How should i call the other constructor to refer self as its object? If there's a reserved word for this i don't know. "inherited" won't do as this case is not a parent class constructor.

    edit: Well, my class seems to work with this technique so i suppose its all ok... It was a class for FrameBuffer, rendering to texture and showing that on screen works

    Code:
    constructor Create(const _texture: integer; _depth: boolean = false);
    
    // This calls above Create with a newly created empty texture
    constructor Create(const width, height: integer; transparency: boolean; _depth: boolean = false);
    Edit2:
    So what i guess is happening is that there is a world of difference with Object.Create and Class.Create. Object.Create will not allocate a new object but instead uses it as a normal procedure. Right?
    Last edited by User137; 05-08-2011 at 03:10 AM.

  2. #2
    Quote Originally Posted by User137 View Post
    So what i guess is happening is that there is a world of difference with Object.Create and Class.Create. Object.Create will not allocate a new object but instead uses it as a normal procedure. Right?
    That's correct. I prefer using Objects for this reason (and also I prefer the more verbose method of dynamically allocating/deallocating memory for them for some reason, i.e. new(myObject, create(param1, param2, ...)) and dispose(myObject, destroy))

  3. #3
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    objects are not well supported and certainly not recomended by delphi or free pascal.

  4. #4
    That's an odd statement. Care to elaborate?

  5. #5
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Well I remember reading a long,long time ago that Object was only there for backward compatibility and not recomended. there is also been bug reports in free pascal about using them. don't think I've ever used them myself so don't really keep up on that to much. what advantages do they offer over classes.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •