PDA

View Full Version : My own class procedure problem



Loodziek
01-12-2007, 05:52 PM
Hi again guys. Well I was try to create my class but I've got a problem. I don't know what's wrong with it, I can't find any answer too... So I post my problem here... You, experienced pascal programmers should know what's wrong, because it's stopping me... Ok, I end of bullshit, now - to the main thing. There's my Lazarus (freepascal) code:


program myclass;

{$mode objfpc}{$H+}


//CLASS TMYCLASS
type
TMyClass = class
private
Started : boolean;
Paused : boolean;

public
constructor Create;
procedure Start;

end;

//TMYCLASS PROCEDURES
constructor TMyClass.Create;
begin
Started := false;
Paused := false;
end;

procedure TMyClass.Start;
begin
Started := true;
Paused := false;
end;

//-----------------------------------
var
Example : TMyClass;

begin
Example.Create;
Example.Start;
ReadLn;
end.


Problem's in TMyClass.Start procedure. When I copy all TMyClass.Start code to TMyClass.Create everything's ok. But what's wrong with it? Anyway, thanks for any replies ;-) Happy pascal coding!

Legolas
01-12-2007, 06:09 PM
...
Example := TMyClass.Create;
Example.Start;
ReadLn;


:)

VilleK
01-12-2007, 06:09 PM
Hello, the normal syntax is this:


var
Example : TMyClass;
begin
Example := TMyClass.Create; //create the object
Example.Start; //do something with it
Example.Free; //release it when done
end.

Loodziek
01-12-2007, 06:16 PM
Dammit! Forgot... I start learning C++ and it's making water from my brain... Thanks a lot guys!