Re: [fpc-pascal] Object constructor

2013-09-17 Thread Michael Van Canneyt



On Tue, 17 Sep 2013, Xiangrong Fang wrote:


Hi All,

Could anyone please explain this:

  5.4 Constructors and destructors

As can be seen in the syntax diagram for an object declaration, Free Pascal 
supports constructors and destructors. The programmer is responsible for 
calling the constructor
and the destructor explicitly when using objects.

My question is, since the programmer is responsible for explicitly call object 
constructors, then why do we need constructors at all?  In another word, what's 
the difference
between an object constructor and an object method?


Using the constructor tells the compiler that it should allocate memory on the 
heap for a new instance,
and return a method to this new memory. There is then an implicit return value for the 
constructor, and this is stored in the variable to which you assign the result of the constructor.


Similarly, the compiler knows that the memory allocated by the constructor must 
be freed again in the destructor.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Object constructor

2013-09-17 Thread Xiangrong Fang
>
> My question is, since the programmer is responsible for explicitly call
>> object constructors, then why do we need constructors at all?  In another
>> word, what's the difference
>> between an object constructor and an object method?
>>
>
> Using the constructor tells the compiler that it should allocate memory on
> the heap for a new instance,
> and return a method to this new memory. There is then an implicit return
> value for the constructor, and this is stored in the variable to which you
> assign the result of the constructor.
>

Well, could you please explain what's the difference between p1 and p2 in
the program below:

  1 program test;
  2 type
  3   TObj = object
  4   public
  5 Value: Integer;
  6 procedure SetValue(AValue: Integer);
  7 constructor Init(AValue: Integer);
  8   end;
  9
 10 procedure TObj.SetValue(AValue: Integer);
 11 begin
 12   Value := AValue;
 13 end;
 14
 15 constructor TObj.Init(AValue: Integer);
 16 begin
 17   Value := AValue;
 18 end;
 19
 20 var
 21   p1, p2 : ^TObj;
 22 begin
 23   New(p1);
 24   p1^.SetValue(1);
 25   WriteLn(p1^.Value);
 26   New(p2, Init(2));
 27   WriteLn(p2^.Value);
 28 end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Object constructor

2013-09-17 Thread Michael Van Canneyt



On Tue, 17 Sep 2013, Xiangrong Fang wrote:


My question is, since the programmer is responsible for explicitly 
call object constructors, then why do we need constructors at all?  In another 
word,
what's the difference
between an object constructor and an object method?


Using the constructor tells the compiler that it should allocate memory on the 
heap for a new instance,
and return a method to this new memory. There is then an implicit return value 
for the constructor, and this is stored in the variable to which you assign the 
result of
the constructor.


Ah.

You are using TP-style objects. Forget what I said then. What I wrote applies 
to classes.

My apologies for the misundestanding.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Object constructor

2013-09-17 Thread Frederic Da Vitoria
2013/9/17 Xiangrong Fang 

>  My question is, since the programmer is responsible for explicitly call
>>> object constructors, then why do we need constructors at all?  In another
>>> word, what's the difference
>>> between an object constructor and an object method?
>>>
>>
>> Using the constructor tells the compiler that it should allocate memory
>> on the heap for a new instance,
>> and return a method to this new memory. There is then an implicit return
>> value for the constructor, and this is stored in the variable to which you
>> assign the result of the constructor.
>>
>
> Well, could you please explain what's the difference between p1 and p2 in
> the program below:
>
>   1 program test;
>   2 type
>   3   TObj = object
>   4   public
>   5 Value: Integer;
>   6 procedure SetValue(AValue: Integer);
>   7 constructor Init(AValue: Integer);
>   8   end;
>   9
>  10 procedure TObj.SetValue(AValue: Integer);
>  11 begin
>  12   Value := AValue;
>  13 end;
>  14
>  15 constructor TObj.Init(AValue: Integer);
>  16 begin
>  17   Value := AValue;
>  18 end;
>  19
>  20 var
>  21   p1, p2 : ^TObj;
>  22 begin
>  23   New(p1);
>  24   p1^.SetValue(1);
>  25   WriteLn(p1^.Value);
>  26   New(p2, Init(2));
>  27   WriteLn(p2^.Value);
>  28 end.
>

(Thanks to Michael for spotting that you are using TP objects)

A little bit below the citation in your first post, you'll find this: "A
constructor/destructor pair is required if the object uses virtual methods.
The reason is that for an object with virtual methods, some internal
housekeeping must be done: this housekeeping is done by the constructor"
:-) In Turbo Pascal, it seems that some VMT housekeeping was also done in
the destructor, I don't know if this is still true in fpc.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] fpc 2.6.3 building i386 crosscompiler fails

2013-09-17 Thread Lukas Gradl

Hi!

Tried to build the current svn of FPC 2.6.3 (svn Revision 25507) on my  
Linux X86_64-box.


I did:
make distclean
make all FPC=
sudo make install PREFIX= FPC=

This worked so far, now I have the current svn as x86_64 compiler.

Then i did:
make clean
make all CPU_TARGET=i386

This produces an error:
fpmkunit.pp(437,17) Error: Forward declaration not solved "constructor  
TPackageVariant.Create(TCollection);"
fpmkunit.pp(438,16) Error: Forward declaration not solved "destructor  
TPackageVariant.Destroy;"
fpmkunit.pp(452,14) Error: Forward declaration not solved  
"TPackageVariants.GetActivePackageVariant:TPackageVariant;"
fpmkunit.pp(453,14) Error: Forward declaration not solved  
"TPackageVariants.GetDefaultPackageVariant:TPackageVariant;"
fpmkunit.pp(454,15) Error: Forward declaration not solved  
"TPackageVariants.SetActivePackageVariantName(AnsiString);"
fpmkunit.pp(455,15) Error: Forward declaration not solved  
"TPackageVariants.SetDefaultPackageVariantName(AnsiString);"
fpmkunit.pp(457,14) Error: Forward declaration not solved  
"TPackageVariants.GetOwner:TPersistent;"
fpmkunit.pp(459,14) Error: Forward declaration not solved  
"TPackageVariants.Add(AnsiString):TPackageVariant;"

fpmkunit.pp(7319) Fatal: There were 8 errors compiling module, stopping

Anyone an idea why?

regards
Lukas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Generic TFPGList gives me compiler error: Operator is not overloaded

2013-09-17 Thread Dennis Poon

I have this:
uses fgl;

Type
  RScene=record
ID : Word;
Name, Category : String;
  end;

  TSceneList=specialize TFPGList;


The error is:  Operator is not overloaded: "RScene" = "RScene"


I suppose the generic thing does not know how to compare 2 records.
How do I solve that?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Generic TFPGList gives me compiler error: Operator is not overloaded

2013-09-17 Thread Sven Barth

On 17.09.2013 14:52, Dennis Poon wrote:

I have this:
uses fgl;

Type
   RScene=record
 ID : Word;
 Name, Category : String;
   end;

   TSceneList=specialize TFPGList;


The error is:  Operator is not overloaded: "RScene" = "RScene"


I suppose the generic thing does not know how to compare 2 records.
How do I solve that?


Provide a "=" operator overload for the record:

=== code begin ===

uses fgl;

{$modeswitch advanced_records}

Type
   RScene=record
 ID : Word;
 Name, Category : String;
 class operator = (aLeft, aRight: RScene): Boolean;
   end;

   TSceneList=specialize TFPGList;

class operator RScene.=(aLeft, aRight: RScene): Boolean;
begin
  ...
end;

=== code end ===

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fpc 2.6.3 building i386 crosscompiler fails

2013-09-17 Thread patspiper

On 17/09/13 15:12, Lukas Gradl wrote:

Hi!

Tried to build the current svn of FPC 2.6.3 (svn Revision 25507) on my 
Linux X86_64-box.


I did:
make distclean
make all FPC=
sudo make install PREFIX= FPC=

This worked so far, now I have the current svn as x86_64 compiler.

Then i did:
make clean
make all CPU_TARGET=i386

This produces an error:
fpmkunit.pp(437,17) Error: Forward declaration not solved "constructor 
TPackageVariant.Create(TCollection);"
fpmkunit.pp(438,16) Error: Forward declaration not solved "destructor 
TPackageVariant.Destroy;"
fpmkunit.pp(452,14) Error: Forward declaration not solved 
"TPackageVariants.GetActivePackageVariant:TPackageVariant;"
fpmkunit.pp(453,14) Error: Forward declaration not solved 
"TPackageVariants.GetDefaultPackageVariant:TPackageVariant;"
fpmkunit.pp(454,15) Error: Forward declaration not solved 
"TPackageVariants.SetActivePackageVariantName(AnsiString);"
fpmkunit.pp(455,15) Error: Forward declaration not solved 
"TPackageVariants.SetDefaultPackageVariantName(AnsiString);"
fpmkunit.pp(457,14) Error: Forward declaration not solved 
"TPackageVariants.GetOwner:TPersistent;"
fpmkunit.pp(459,14) Error: Forward declaration not solved 
"TPackageVariants.Add(AnsiString):TPackageVariant;"

fpmkunit.pp(7319) Fatal: There were 8 errors compiling module, stopping

Anyone an idea why?


Seems to be related to a missing/wrong/extra define of NO_UNIT_PROCESS 
or HAS_UNIT_PROCESS in fpmkunit.pp.


Stephano
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPCUnit test + raise E;

2013-09-17 Thread Marcos Douglas
On Tue, Sep 17, 2013 at 12:18 PM, Marcos Douglas  wrote:
> On Sun, Sep 15, 2013 at 4:25 PM, Sven Barth  
> wrote:
>> On 15.09.2013 13:05, Marcos Douglas wrote:
>>>
>>> [[cut]]
>>>
>>>
>>> I tried. No makes difference.
>>> (could you explain which the difference to call "raise" using "raise E
>>> at [...]"?)
>>
>>
>> The raise-at statement allows you to raise an exception for a specific
>> address. This allows you to have e.g. a error handling procedure (to wrap a
>> more compilated generation of a exception class) but have the exception
>> address still point to the original call site. E.g.:
>>
>> === code begin ===
>>
>> procedure Error(aArg: Boolean);
>> begin
>>   if aArg then
>> raise Exception.Create('Test')
>>   else
>> raise Exception.Create('Test') at get_caller_addr(get_frame),
>> get_caller_frame(get_frame);
>> end;
>>
>> procedure Test1;
>> begin
>>   Error(True);
>> end;
>>
>> procedure Test2;
>> begin
>>   Error(False);
>> end;
>>
>> begin
>>   try
>> Test1;
>>   except
>> DumpExceptionBackTrace(Output);
>>   end;
>>   try
>> Test2;
>>   except
>> DumpExceptionBackTrace(Output);
>>   end;
>> end;
>>
>> === code end ===
>>
>> In case one the stack trace will contain Test1 and Error in case two the
>> stack trace will be only Test2.
>
> Ok, thanks for the explanation!
>
>
>>> I implemented -- but not up to Git yet -- some like that:
>>> procedure TghSQLHandler.DoOnException(E: Exception);
>>> var
>>>NewEx: EghSQLError;
>>> begin
>>>if Assigned(FOnException) then
>>>  FOnException(Self, E)
>>>else
>>>begin
>>>  NewEx := EghSQLError.Create(Self, E.Message);   // <<<
>>>  NewEx.InnerException := E;  // <<<
>>>  raise NewEx;
>>>end;
>>> end;
>>>
>>> So, if I recreate the Exception, it works in any cases. As you see, I
>>> created a new property (InnerException) to save the original
>>> exception to know what the real Exception happened...
>>> But I think this introduces much more overhead to processing.
>>
>>
>> Can you access fields of the InnerException? Maybe it's a problem of
>> reraising an existing exception...
>
> Yes, I have access but no, this is not the problem. I had coded
> InnerException property after the problem to solve it, creating a new
> Exception but not missing the original one.
>
>
>>> In my code I have classes that inherited from TghSQLHandler. This
>>> class have the DoOnException method.
>>> So DoOnException can be call many times in override methods. Maybe the
>>> program "broke" the stack because "raise E" can be call and raise an
>>> exception; the next "level" raise another; and next call again.  :/
>>
>>
>> Could possibly be. If you could reproduce it in an as simple example as
>> possible that would help.
>
>
> !
> In attachment.
> !
>
>
>
>> Another thing you could try (just for testing): change your exception
>> handler procedure to a function that returns bool and use it like this:
>>
>> === code begin ===
>>
>>
>> procedure TghSQLConnector.Connect;
>> begin
>>   try
>> FLib.Connect;
>>   except
>> on E: Exception do
>>   if not DoOnException(E) then
>> raise;
>>   end;
>> end;
>>
>> === code end ===
>>
>>
>> Regards,
>> Sven
>
> The only difference is the use of raise; instead raise E; right?
>
> Marcos Douglas

In project in attachment before, if you change the line 50
from:
raise E;

to:
raise Exception.Create(E.Message);

Will work... but is this correct?


Lazarus 1.1 r42461 FPC 2.6.2 i386-win32-win32/win64

Best regards,
Marcos Douglas

PS: Sorry for my late, Sven.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Lubomír Čabla
I am doing something wrong?

When I encode the date and time then for SecondsBetween
I get 59 instead of 60 and for MilliSecondsBetween also.
When I encode only time then for SecondsBetween I get correct answer 60.

Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Target: GO32 v2, i386

Results from dt.pp:

ShortDateFormat=d/m/y
LongDateFormat=dd" "" "
ShortTimeFormat=hh:nn
LongTimeFormat=hh:nn:ss

Encode date and time:
DateTime DT1= 28.05.2013 15:26:01:0
DateTime DT2= 28.05.2013 15:27:01:0
Between DT2-DT1= 0.0:0:59:5

Encode time only:
DateTime DT1= 30.12.1899 15:26:01:0
DateTime DT2= 30.12.1899 15:27:01:0
Between DT2-DT1= 0.0:1:60:6

Btw. FormatDateTime('dd.mm. hh:nn:ss:z',DT1));

the result is the same with the use 'mm' instead of 'nn' for minutes:

FormatDateTime('dd.mm. hh:mm:ss:z',DT1));

Lubomir Cabla


dt.pp
Description: Binary data
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Bart
On 9/17/13, Lubomír Čabla  wrote:
> I am doing something wrong?

Probably rounding errors:
  DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0);
2 calculations on floating numbers

  DT1:=EncodeTime(15,26,1,0);
1 calculation on floating numbers

Bart
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Generic TFPGList gives me compiler error: Operator is not overloaded

2013-09-17 Thread Dennis Poon

Sven,

Thanks a lot. It worked.

Generics, advanced record, customized operator ... all these new 
features are so cool.

I am impressed that Free Pascal has become so powerful.

Dennis


uses fgl;


Type
   RScene=record
 ID : Word;
 Name, Category : String;
   end;

   TSceneList=specialize TFPGList;


The error is:  Operator is not overloaded: "RScene" = "RScene"


I suppose the generic thing does not know how to compare 2 records.
How do I solve that?


Provide a "=" operator overload for the record:





___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPCUnit test + raise E;

2013-09-17 Thread Sven Barth

On 17.09.2013 17:27, Marcos Douglas wrote:

On Tue, Sep 17, 2013 at 12:18 PM, Marcos Douglas  wrote:

Another thing you could try (just for testing): change your exception
handler procedure to a function that returns bool and use it like this:

=== code begin ===


procedure TghSQLConnector.Connect;
begin
   try
 FLib.Connect;
   except
 on E: Exception do
   if not DoOnException(E) then
 raise;
   end;
end;

=== code end ===


Regards,
Sven


The only difference is the use of raise; instead raise E; right?

Marcos Douglas


In project in attachment before, if you change the line 50
from:
 raise E;

to:
 raise Exception.Create(E.Message);

Will work... but is this correct?


So this seems to be indeed a problem of freeing exceptions. Whether you 
misuse the exception system or you encountered a bug needs to be 
determined...



Lazarus 1.1 r42461 FPC 2.6.2 i386-win32-win32/win64


Could you test your original one with 2.7.1 as well?


PS: Sorry for my late, Sven.


No problem. :)

Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Generic TFPGList gives me compiler error: Operator is not overloaded

2013-09-17 Thread Sven Barth

On 17.09.2013 17:39, Dennis Poon wrote:

Sven,

Thanks a lot. It worked.

Generics, advanced record, customized operator ... all these new
features are so cool.
I am impressed that Free Pascal has become so powerful.


At least generics and operator overloads aren't that new. What's new is 
that generics contain less bugs (at least in 2.7.1 compared to earlier 
versions) and that operators can be used inside records (together with 
normal methods).


Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Lubomír Čabla
It may be, but I tried to use EncodeDateTime with the same result:

DT1:=EncodeDateTime(2013,5,28,15,26,1,0);
DT2:=EncodeDateTime(2013,5,28,15,27,1,0);

Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate and
TryEncodeTime.

This is only a test, I want to be sure that after comparing the two values
​​get the correct time difference and 59 seconds is not correct.


On Tue, Sep 17, 2013 at 6:15 PM, Bart  wrote:

> On 9/17/13, Lubomír Čabla  wrote:
> > I am doing something wrong?
>
> Probably rounding errors:
>   DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0);
> 2 calculations on floating numbers
>
>   DT1:=EncodeTime(15,26,1,0);
> 1 calculation on floating numbers
>
> Bart
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] FPCUnit test + raise E;

2013-09-17 Thread Sven Barth

On 17.09.2013 17:18, Marcos Douglas wrote:

I implemented -- but not up to Git yet -- some like that:
procedure TghSQLHandler.DoOnException(E: Exception);
var
NewEx: EghSQLError;
begin
if Assigned(FOnException) then
  FOnException(Self, E)
else
begin
  NewEx := EghSQLError.Create(Self, E.Message);   // <<<
  NewEx.InnerException := E;  // <<<
  raise NewEx;
end;
end;

So, if I recreate the Exception, it works in any cases. As you see, I
created a new property (InnerException) to save the original
exception to know what the real Exception happened...
But I think this introduces much more overhead to processing.



Can you access fields of the InnerException? Maybe it's a problem of
reraising an existing exception...


Yes, I have access but no, this is not the problem. I had coded
InnerException property after the problem to solve it, creating a new
Exception but not missing the original one.


Was just an idea that something got freed while you didn't expect it to 
get freed...



In my code I have classes that inherited from TghSQLHandler. This
class have the DoOnException method.
So DoOnException can be call many times in override methods. Maybe the
program "broke" the stack because "raise E" can be call and raise an
exception; the next "level" raise another; and next call again.  :/



Could possibly be. If you could reproduce it in an as simple example as
possible that would help.



!
In attachment.
!


Will take a look when I find the time (or someone else of the devs can 
take a look as well ^^)



Another thing you could try (just for testing): change your exception
handler procedure to a function that returns bool and use it like this:

=== code begin ===


procedure TghSQLConnector.Connect;
begin
   try
 FLib.Connect;
   except
 on E: Exception do
   if not DoOnException(E) then
 raise;
   end;
end;

=== code end ===


Regards,
Sven


The only difference is the use of raise; instead raise E; right?


Basically, yes. But "raise;" can only be used inside an "except ... end" 
block, so it would not compile inside your DoOnException method.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Tomas Hajny
On Tue, September 17, 2013 20:22, Lubomír Čabla wrote:
> It may be, but I tried to use EncodeDateTime with the same result:
>
> DT1:=EncodeDateTime(2013,5,28,15,26,1,0);
> DT2:=EncodeDateTime(2013,5,28,15,27,1,0);
>
> Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate
> and
> TryEncodeTime.
>
> This is only a test, I want to be sure that after comparing the two values
> ​​get the correct time difference and 59 seconds is not correct.

As a principle, you can never avoid such errors if using floating point
numbers. If you need absolutely precise results, use integers.

Tomas


>
> On Tue, Sep 17, 2013 at 6:15 PM, Bart  wrote:
>
>> On 9/17/13, Lubomír Čabla  wrote:
>> > I am doing something wrong?
>>
>> Probably rounding errors:
>>   DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0);
>> 2 calculations on floating numbers
>>
>>   DT1:=EncodeTime(15,26,1,0);
>> 1 calculation on floating numbers
>>
>> Bart
>> ___
>> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Object constructor

2013-09-17 Thread Florian Klämpfl
Am 17.09.2013 09:44, schrieb Xiangrong Fang:
> My question is, since the programmer is responsible for
> explicitly call object constructors, then why do we need
> constructors at all?  In another word, what's the difference
> between an object constructor and an object method?
> 
> 
> Using the constructor tells the compiler that it should allocate
> memory on the heap for a new instance,
> and return a method to this new memory. There is then an implicit
> return value for the constructor, and this is stored in the variable
> to which you assign the result of the constructor.
> 
> 
> Well, could you please explain what's the difference between p1 and p2
> in the program below:

You cannot use fail outside of a constructor. So there is no proper
error handling method available which does no create memory leaks.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Lubomír Čabla
Yes, I know, you are right, so far I've used DOS utility GetDate/GetTime
without any errors.

I wanted to update the old compiler 1.x to the new version, but it seems
will stay with the old version.

Thank you for your help.



On Tue, Sep 17, 2013 at 8:31 PM, Tomas Hajny  wrote:

> On Tue, September 17, 2013 20:22, Lubomír Čabla wrote:
> > It may be, but I tried to use EncodeDateTime with the same result:
> >
> > DT1:=EncodeDateTime(2013,5,28,15,26,1,0);
> > DT2:=EncodeDateTime(2013,5,28,15,27,1,0);
> >
> > Function EncodeDateTime calls TryEncodeDateTime that uses TryEncodeDate
> > and
> > TryEncodeTime.
> >
> > This is only a test, I want to be sure that after comparing the two
> values
> > get the correct time difference and 59 seconds is not correct.
>
> As a principle, you can never avoid such errors if using floating point
> numbers. If you need absolutely precise results, use integers.
>
> Tomas
>
>
> >
> > On Tue, Sep 17, 2013 at 6:15 PM, Bart  wrote:
> >
> >> On 9/17/13, Lubomír Čabla  wrote:
> >> > I am doing something wrong?
> >>
> >> Probably rounding errors:
> >>   DT1:=EncodeDate(2013,5,28)+EncodeTime(15,26,1,0);
> >> 2 calculations on floating numbers
> >>
> >>   DT1:=EncodeTime(15,26,1,0);
> >> 1 calculation on floating numbers
> >>
> >> Bart
> >> ___
> >> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >>
> > ___
> > fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] FPC 2.6.2 for DOS/Go32V2 FP.EXE cannot run a second time

2013-09-17 Thread Lubomír Čabla
FPC 2.6.2 for DOS/Go32V2

There is the fatal IDE unstability in FPC 2.6.2 under pure DOS.

IDE almost always starts only first time (after installation or reboot).
I start the IDE, compile and run the program (e.g. Hello.pas) and close
IDE. But when I want to start IDE again it crashes with SIGSEGV message.

 Exiting due to signal SIGSEGV
 FPC General Protection Fault at eip=006EDE95
 eax=65672D6C ebx=002A ecx=0088 edx= esi=008E91F8
edi=0083B504
 ebp=008C0CA0 esp=008C0C90 program=C:\PP\BIN\GO32V2\FP.EXE
 cs: sel=00A7 base=0040 limit=008E
 ds: sel=00AF base=0040 limit=008E
 es: sel=00AF base=0040 limit=008E
 fs: sel=00C7 base= limit=0010
 gs: sel=00C7 base= limit=0010
 ss: sel=00AF base=0040 limit=008E

 Call frame traceback EIPs:
 $006EDE95
 $005BD905
 $005BCD84
 $005BC83D
 $005BC7F8
 $00308AF8
 $0030B9F4
 $0002DB50
 $0002DC5A
 $2040

To be able to start IDE again in DOS I have to reboot the computer.
I think IDE set something in memory and warm restart does not erase the
memory contents.

Compilation from command prompt with FPC.EXE works everywhere.
But IDE is good for debugging and help.

Can someone please help me or advise what I'm doing wrong.

The main problem is running IDE in pure DOS.

Thank you.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Re: Generic TFPGList gives me compiler error: Operator is not overloaded

2013-09-17 Thread leledumbo
> and that operators can be used inside records

I just knew this one :)



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Generic-TFPGList-Record-Type-gives-me-compiler-error-Operator-is-not-overloaded-tp5716520p5716541.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC GO32 2.6.2 wrong result from SecondsBetween

2013-09-17 Thread Tomas Hajny
On Tue, September 17, 2013 20:51, Lubomír Čabla wrote:
> Yes, I know, you are right, so far I've used DOS utility GetDate/GetTime
> without any errors.
>
> I wanted to update the old compiler 1.x to the new version, but it seems
> will stay with the old version.

There should be no problem to continue using GetDate/GetTime with current
FPC version.

Tomas



>
> On Tue, Sep 17, 2013 at 8:31 PM, Tomas Hajny  wrote:
>
>> On Tue, September 17, 2013 20:22, Lubomír Čabla wrote:
>> > It may be, but I tried to use EncodeDateTime with the same result:
>> >
>> > DT1:=EncodeDateTime(2013,5,28,15,26,1,0);
>> > DT2:=EncodeDateTime(2013,5,28,15,27,1,0);
>> >
>> > Function EncodeDateTime calls TryEncodeDateTime that uses
>> TryEncodeDate
>> > and
>> > TryEncodeTime.
>> >
>> > This is only a test, I want to be sure that after comparing the two
>> values
>> > get the correct time difference and 59 seconds is not correct.
>>
>> As a principle, you can never avoid such errors if using floating point
>> numbers. If you need absolutely precise results, use integers.
>>
>> Tomas


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC 2.6.2 for DOS/Go32V2 FP.EXE cannot run a second time

2013-09-17 Thread Tomas Hajny
On Tue, September 17, 2013 20:57, Lubomír Čabla wrote:
> FPC 2.6.2 for DOS/Go32V2
>
> There is the fatal IDE unstability in FPC 2.6.2 under pure DOS.
>
> IDE almost always starts only first time (after installation or reboot).
> I start the IDE, compile and run the program (e.g. Hello.pas) and close
> IDE. But when I want to start IDE again it crashes with SIGSEGV message.
>
>  Exiting due to signal SIGSEGV
>  FPC General Protection Fault at eip=006EDE95
>  eax=65672D6C ebx=002A ecx=0088 edx= esi=008E91F8
> edi=0083B504
>  ebp=008C0CA0 esp=008C0C90 program=C:\PP\BIN\GO32V2\FP.EXE
>  cs: sel=00A7 base=0040 limit=008E
>  ds: sel=00AF base=0040 limit=008E
>  es: sel=00AF base=0040 limit=008E
>  fs: sel=00C7 base= limit=0010
>  gs: sel=00C7 base= limit=0010
>  ss: sel=00AF base=0040 limit=008E
>
>  Call frame traceback EIPs:
>  $006EDE95
>  $005BD905
>  $005BCD84
>  $005BC83D
>  $005BC7F8
>  $00308AF8
>  $0030B9F4
>  $0002DB50
>  $0002DC5A
>  $2040
>
> To be able to start IDE again in DOS I have to reboot the computer.
> I think IDE set something in memory and warm restart does not erase the
> memory contents.
>
> Compilation from command prompt with FPC.EXE works everywhere.
> But IDE is good for debugging and help.
>
> Can someone please help me or advise what I'm doing wrong.
>
> The main problem is running IDE in pure DOS.

Which DOS version is it? Is there any DPMI provider running before
starting the IDE (some DOS versions include DPMI host themselves)?

If there is no other DPMI host (running) and thus CWSDPMI.EXE is used, I'd
recommend starting with a check whether there is just one (the latest)
CWSDPMI.EXE and just for test purposes try loading it into memory as TSR
with options "-p -x" (see cwsdpmi.txt included in directory doc\fpc) to
see if it makes any difference.

Obviously, the next step would be compiling the IDE with debug information
(including -gl) to see where exactly it fails.

Tomas


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal