PDA

View Full Version : "SIGSEGV" error : How do I do OOP correctly?



I_am_root
29-07-2006, 01:19 AM
I'm new to FP even if I programmed in Basic and BP before.

I tried some stuff like this :


Unit MyUnit;

{$MODE DELPHI}


INTERFACE

uses classes;

Type TMyObj = class
Public
a : Integer;
End;

IMPLEMENTATION

End.


...and the test program...



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

Var
MyObj : TMyObj;

Begin

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

End.




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

Thx in advance.

________________
Regards,
Eduard

dmantione
29-07-2006, 08:32 AM
You didn't create any object, so variable myobj is undefined. Create one first.

Clootie
29-07-2006, 10:56 AM
Does FPC support "object" style (old TurboPascal) classes?

dmantione
29-07-2006, 12:06 PM
Of course it does :) Just use "object" instead of "class", and the compiler will know what to do with it.

I_am_root
30-07-2006, 03:11 PM
Many thanks, dmantione :D. It works perfectly now.



_________________
Regards,
Eduard

WILL
30-07-2006, 11:04 PM
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 (http://www.webtechcorp.co.uk/web-developer-training-delphi-article-oop.htm)
Essential Pascal (http://www.marcocantu.com/epascal/English/)

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.