Sign in Join

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

Mailing lists / fpc-pascal / 2003-11

class methods in FPC version 1.9.0

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

dean

When porting a Kylix/Delphi project to FPC (version 1.9.0 Linux) I've encountered this small problem using class methods: When I pass an object instance as parameter in class methods I have a sigsev like in this example

program TestFail;
uses
  SysUtils;
Type
  TMyObject = Class
  private
    FNome: string;
  published
    Property Nome: string read FNome write FNome;
  end;
  TMyTestObject = class(TObject)
  public
    class function OutputParticularClass(AObj: TObject):string;
  end;
var
  obj: TMyObject;
class function TMyTestObject.OutputParticularClass(AObj: TObject): string;
begin
  Result := AObj.ClassName;
  Writeln(Result);
end;
begin
  obj := TMyObject.Create;
  TMyTestObject.OutputParticularClass(obj);
  obj.Free;
end.

The above program compiles with no warnings in FPC, but at runtime it sigsevs. I've run this in Kylix/Delphi and works as expected.

On the other hand I've seen that class methods work ok if the parameter passed are integers for example

class function TMyTestObject.OutputNumber(aNumber: integer):string;
begin
  Result := 'Number is ' + intToStr(aNumber);
  Writeln(Result);
end;
begin
  TMyTestObject.OutputNumber(12345);
end.
works ok in FPC

Am I doing something wrong or is a bug I've found? Any ideas?

Ciao, Dean

Marco van de Voort
to dean
When porting a Kylix/Delphi project to FPC (version 1.9.0 Linux) I've encountered this small problem using class methods: When I pass an object instance as parameter in class methods I have a sigsev like in this example

Hmm, here it returns

-bash-2.05b$ ./bugtest
TMyObject
-bash-2.05b$

with

Free Pascal Compiler version 1.9.1

Compiler Date : 2003/11/11
Compiler Target: i386

on FreeBSD

So it could be it that is already fixed after 1.9.0

Peter Vreman
to dean: When porting a Kylix/Delphi project to FPC (version 1.9.0 Linux) I've encountered this…
Show quoted text 7 lines
When porting a Kylix/Delphi project to FPC (version 1.9.0 Linux) I've encountered this small problem using class methods: When I pass an object instance as parameter in class methods I have a sigsev like in this example Am I doing something wrong or is a bug I've found?

It was a bug in the compiler. It is already fixed a few days ago.

Thanks for reporting.

Peter

Dean Zobec
to Marco van de Voort: Hmm, here it returns -bash-2.05b$ ./bugtest TMyObject -bash-2.05b$ with Free Pascal…
Show quoted text 15 lines
Hmm, here it returns -bash-2.05b$ ./bugtest TMyObject -bash-2.05b$ with Free Pascal Compiler version 1.9.1 Compiler Date : 2003/11/11 Compiler Target: i386 on FreeBSD So it could be it that is already fixed after 1.9.0

Great, :-)
One more question, where can I find the version 1.9.1 ? What would you suggest me as the best way to be up to date ? I just checked out the cvs tree, should I update it once in a while and build the compiler? Any instructions available?
Thanks again to all of you at Free Pascal, you are great! Ciao, Dean

Marco van de Voort
to Dean Zobec
Show quoted text 10 lines
> Free Pascal Compiler version 1.9.1 > > Compiler Date : 2003/11/11 > Compiler Target: i386 > > on FreeBSD > So it could be it that is already fixed after 1.9.0 Great, :-) One more question, where can I find the version 1.9.1 ?

Versions with an odd third numbers are development versions that only exist in CVS.

What would you suggest me as the best way to be up to date ? I just checked out the cvs tree, should I update it once in a while and build the compiler? Any instructions available? Thanks again to all of you at Free Pascal, you are great! Ciao, Dean

That is the easiest way I think. The next beta release is planned for December at its earliest.

See also http://www.stack.nl/~marcov/buildfaq.pdf for some pointers about building the FPC cvs.

Dean Zobec
to Marco van de Voort
See also http://www.stack.nl/~marcov/buildfaq.pdf for some pointers about building the FPC cvs.

Thank you for the tutorial, it helped me a lot. It was exciting to see the compiler building process on the screen :-) So now I have a 1.9.1 for i386 Linux!
I have encountered a problem when doing a "make all" from the cvs tree (checked out yesterday) that maybe is worth mentioning: when compiling pipes.pp i've got an error in pipes.inc (/usr/local/src/fpc/devel/fpc/fcl/unix/pipes.inc)
got longint expected boolean

Uses
{$ifdef ver1_0}
  Linux
{$else}
  Unix
{$endif}
  ;
Function CreatePipeHandles (Var Inhandle,OutHandle : Longint) : Boolean;
begin
  Result := AssignPipe (Inhandle,OutHandle);
end;

{
$Log: pipes.inc,v $
Revision 1.5 2002/09/07 15:15:29 peter
* old logs removed and tabs fixed

}

I did a simple typecast:
Result := Boolean(AssignPipe (Inhandle,OutHandle)); and all went well in the next "make all"

Hope I didn't broke something else with this typecast.

Thank you again for all the help. Hope to be able to make up some day with a humble contribution to the project. :-)
Btw I was thinking about beginning a port of the JUnit testing framework to Free Pascal, as I'm no longer feeling safe without a unit testing net when programming. Could it be interesting? Or it's been already done?

Ciao, Dean

Marco van de Voort
to Dean Zobec
> See also http://www.stack.nl/~marcov/buildfaq.pdf for some pointers about > building the FPC cvs. Thank you for the tutorial, it helped me a lot. It was exciting to see the ;

(unit Unix is something that I'm working on atm)

Show quoted text 5 lines
I did a simple typecast: Result := Boolean(AssignPipe (Inhandle,OutHandle)); and all went well in the next "make all" Hope I didn't broke something else with this typecast.

The typecast is incorrect. It should be

Result:=(AssignPipe(..)-1);

I'll fix this later this morning, thanks for reporting.

Show quoted text 5 lines
Thank you again for all the help. Hope to be able to make up some day with a humble contribution to the project. :-) Btw I was thinking about beginning a port of the JUnit testing framework to Free Pascal, as I'm no longer feeling safe without a unit testing net when programming. Could it be interesting? Or it's been already done?

Jedi has a Delphi port of JUnit called DUnit, but I doubt it will work, it meddles too much with the internals of objects.

Dean Zobec
to Marco van de Voort
The typecast is incorrect. It should be Result:=(AssignPipe(..)-1);

Thank you.

I'll fix this later this morning, thanks for reporting.

It's a pleasure :-) Thank you for the fix.

Delphi port of JUnit called DUnit, but I doubt it will work, it meddles too much with the internals of objects.

I've used it for a year or so, the Juanco's DUnit
http://dunit.sourceforge.net/ it's good but maybe too complicated and differs from the JUnit framework in some important parts to leverage the potential of Delphi against Java. I'm not quite sure of the real benefits. I think it misses the good idea of Assert class methods that makes it easy to use Mock Objects.
Another more recent version is xUnit4Delphi, written more closely to the original design. And finally a visual testing suite written by a friend of mine, Mike Johnson http://www.bigattichouse.com/qtest.php, but I'm much more oriented towards a console testing framework.
I'll try to study all of the designs more closely. Ciao, Dean

Vincent Snijders
to Marco van de Voort: (unit Unix is something that I'm working on atm) The typecast is incorrect. It should be…
Show quoted text 7 lines
> Btw I was thinking about beginning a port of the JUnit testing > framework to Free Pascal, as I'm no longer feeling safe without a > unit testing net when programming. Could it be interesting? Or it's > been already done? Jedi has a Delphi port of JUnit called DUnit, but I doubt it will work, it meddles too much with the internals of objects.

I am trying to port the DUnit test framework to fpc and lazarus, see for more info
http://lazarus-ccr.sourceforge.net/index.php?wiki=DunitProject.

The testframework unit compiles and I don't see to many troubles with the text test runner. I am still a bit in a doubt, if it would be possible to put the test classes in a library and make the path to library a command line argument. I have to do some research to find out to what level fpc supports libraries.

Vincent.

Dean Zobec
to Vincent Snijders
I am trying to port the DUnit test framework to fpc and lazarus, see for more info http://lazarus-ccr.sourceforge.net/index.php?wiki=DunitProject.

I'll take a look

The testframework unit compiles

I was able to compile it too, but I have still a lot of work to make it work I guess ;-)

and I don't see to many troubles with the text test runner.

yes that's the easy part

library a command line argument. I have to do some research to find out to what level fpc supports libraries.

From what I've seen in the first three days with fpc, I think you'll have no problems. :-)
Ciao, Dean