Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-07

Initialize the object (not class)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zaher Dirkey

I have used object to make more easy, not need to create or free it,

MyObject = object
private
  FProp1: integer;
public
  Prop1: integer read FProp1 write FProp1
  procedure Proc1;
end;
used like
var
  O: MyObject;
begin
  O.Proc1;
end;

1 - The problem, i have random value in the prop1(I am not sure about it), is that mean i must initiliaze it.
2 - is there a method i can override it to init my properties without to call it manualy O.init;

Thanks in advance

Zaher Dirkey

Reply by email

Jonas Maebe
to Zaher Dirkey
Zaher Dirkey wrote 17 lines
MyObject = object private FProp1: integer; public Prop1: integer read FProp1 write FProp1 procedure Proc1; end; used like var O: MyObject; begin O.Proc1; end; 1 - The problem, i have random value in the prop1(I am not sure about it), is that mean i must initiliaze it.

That's correct. An object is basically the same as a record, except that it can have methods (although in later Delphi versions, records also can have methods).

2 - is there a method i can override it to init my properties without to call it manualy O.init;

No.

Jonas

Reply by email