Results 1 to 6 of 6

Thread: "SIGSEGV" error : How do I do OOP correctly?

  1. #1

    "SIGSEGV" error : How do I do OOP correctly?

    I'm new to FP even if I programmed in Basic and BP before.

    I tried some stuff like this :

    [pascal]
    Unit MyUnit;

    {$MODE DELPHI}


    INTERFACE

    uses classes;

    Type TMyObj = class
    Public
    a : Integer;
    End;

    IMPLEMENTATION

    End.
    [/pascal]

    ...and the test program...

    [pascal]

    Program MyBuggyProgram;
    {$MODE DELPHI}
    uses classes, crt;

    Var
    MyObj : TMyObj;

    Begin

    clrscr;
    Write(MyObj.a); // SIGSEGV
    Readkey;

    End.


    [/pascal]

    You'll get SIGSEGV. How do I do this correctly?

    Thx in advance.

    ________________
    Regards,
    Eduard

  2. #2

    "SIGSEGV" error : How do I do OOP correctly?

    You didn't create any object, so variable myobj is undefined. Create one first.

  3. #3

    "SIGSEGV" error : How do I do OOP correctly?

    Does FPC support "object" style (old TurboPascal) classes?
    There are only 10 types of people in this world; those who understand binary and those who don't.

  4. #4

    "SIGSEGV" error : How do I do OOP correctly?

    Of course it does Just use "object" instead of "class", and the compiler will know what to do with it.

  5. #5

    "SIGSEGV" error : How do I do OOP correctly?

    Many thanks, dmantione . It works perfectly now.



    _________________
    Regards,
    Eduard

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    "SIGSEGV" error : How do I do OOP correctly?

    Here are a few tutorials that I recommend giving a read. Object Pascal is a different animal from Pascal. The main thing is the concept of Objects and structures in your code. Once you learn this though, you'll love 'em. It even makes some of your code much more powerful and easier to impliment stuff once done right. It just takes some time to get used to the concept of OOP.

    Object Oriented Programming in Delphi - A Guide for Beginners
    Essential Pascal

    There is more material in the PGD Library, you are more than welcome to visit and read through everything. Some other languages are available for some items, but it's mostly in english though.
    Jason McMillen
    Pascal Game Development
    Co-Founder





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
  •