Re: [fpc-pascal] fpwrite buffers issues

2007-10-12 Thread Vincent Snijders

ik schreef:

Hi Sorry for the delay in responding



Some remarks at first glance:
for m := 0 to readcount do
Should be:
for m := 0 to readcount-1 do

It would better to use either cshort or smallint.

I think fpread and fpwrite expect sizes in bytes and not in cshorts (or is a cshort 
1 byte).


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


Re: [fpc-pascal] fpwrite buffers issues

2007-10-12 Thread ik
Hi Sorry for the delay in responding

On 10/8/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:
> ik schreef:
>
> > Hello List,
>
> 
>
> >
> > Then I tried to do the following code, that continue to write the
> > buffer content until nothing more to write, but it reads wrong data:
> >
> > start_count  := 0;
> > output_count := readcount * sizeof(cshort);
> > read_content := read_content_from([EMAIL PROTECTED], MAX_BUFFER);
> > while (read_content > 0) do
> >  begin
> >while (write_count > 0) do
> >  begin
> >write_count := fpwrite (fd, @Buffer[start_count], output_count);
> >if (write_count > 0) then
> >   begin
> > dec (output_count, write_count);
> > inc (start_count, write_count);
> >   end ;
> > end;
> // this seems missing:
> start_count  := 0;
> output_count := readcount * sizeof(cshort);

Well it was missing from my PoC :) but the problem still exists.
I'm attaching the full program (it goes to libsdnfile).

>
> >read_content := read_content_from([EMAIL PROTECTED], MAX_BUFFER);
> > end;
> >
> > I'm using ubuntu Linux amd64 using FPC 2.2.0
> >
>
> Vincent

Thank you,
Ido
-- 
http://ik.homelinux.org/


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

[fpc-pascal] class declaration questions

2007-10-12 Thread Marc Santhoff
Hi,

the reference manual is not explicitly clear in describing class
declarations. Is it true for classes as for objects that the first block
of components after the class header are visible as if declared public?

E.g.

TAnyClass = class
fField:anytype;
end;

would make fField visible "public"?

And one other question:
Does object pascal allow a class declaration marked as an abstract
class? Like in java for making sure the class can never be instantiated
itself, only it's descendants can be?

Smth. like:

TAnyClass = abstract class(...)
 ...
end;

TIA,
Marc


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


Re: [fpc-pascal] Specifying a Interface type via $Interfaces

2007-10-12 Thread Dean Zobec
2007/10/11, Graeme Geldenhuys <[EMAIL PROTECTED]>:
> On 11/10/2007, Dean Zobec <[EMAIL PROTECTED]> wrote:
> > > interface types.  Could somebody please explain the difference.  And
> > > why would I use one over the other?
> > Corba interfaces are not reference counted as they don't descend from 
> > IUnknown
>
> So other than that, COM interfaces and CORBA interfaces share the same 
> features?
> As for reference counting - that just means that as soon as the
> reference count for an Interfaces reaches zero, it gets automatically
> freed?
for a good example of refcounting interfaces you can take a look at
the money.pp fpcunit example and the relative tests.
fcl-fpcunit/src/exampletests/money.pp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Felipe Monteiro de Carvalho
On 10/12/07, Marc Santhoff <[EMAIL PROTECTED]> wrote:
> Does object pascal allow a class declaration marked as an abstract
> class? Like in java for making sure the class can never be instantiated
> itself, only it's descendants can be?

The compiler will issue a warning if you instantiate a class with
abstract methods

-- 
Felipe Monteiro de Carvalho
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Vincent Snijders

Marc Santhoff schreef:

Hi,

the reference manual is not explicitly clear in describing class
declarations. Is it true for classes as for objects that the first block
of components after the class header are visible as if declared public?

E.g.

TAnyClass = class
fField:anytype;
end;

would make fField visible "public"?


It would be "published".



And one other question:
Does object pascal allow a class declaration marked as an abstract
class? Like in java for making sure the class can never be instantiated
itself, only it's descendants can be?

Smth. like:

TAnyClass = abstract class(...)
 ...
end;



AFAIK, not.

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


Re: [fpc-pascal] Specifying a Interface type via $Interfaces

2007-10-12 Thread Dean Zobec
2007/10/11, Graeme Geldenhuys <[EMAIL PROTECTED]>:
> On 11/10/2007, Dean Zobec <[EMAIL PROTECTED]> wrote:
> > > interface types.  Could somebody please explain the difference.  And
> > > why would I use one over the other?
> > Corba interfaces are not reference counted as they don't descend from 
> > IUnknown
>
> So other than that, COM interfaces and CORBA interfaces share the same 
> features?
yes IIRC
> As for reference counting - that just means that as soon as the
> reference count for an Interfaces reaches zero, it gets automatically
> freed?
yes, though you have to pay much attention to memory leaks and
possible problems when dealing a lot with interfaces, memory leaks
should be monitored closely.

 CORBA then rather treats them like classes - you can have no
> other objects referencing the class, yet it stays in memory. You
> always need to free it off manually.
Yes, like dealing with normal objects.
> > point of view see this chapter of Delphi in a Nutshell by By Ray
> > Lischner:
> > http://www.oreilly.com/catalog/delphi/chapter/ch02.html
>
> Thanks for the link and quote. It already makes more sense.  Hopefully
> more reading about the topic will strengthen the knowledge when to use
> Interfaces and when to use Class Inheritance.
>
> > I'll try to find some old links about articles I've read years ago.
>
> That will be very much appreciated. Thanks.
Time has deleted a lot of web links, funny how much data and knowledge
gets lost when the webspace is gone.
I'm sure I'll be able to find something shuffling from the old delphi
CDs or papers.
A good article about the use of interfaces in free pascal is really
needed. I think interfaces are a very powerful oop feature. If only I
had time :(

regards,
Dean


>
> Regards,
>   - Graeme -
>
>
> ___
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> ___
> 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] class declaration questions

2007-10-12 Thread Mattias Gaertner
On Fri, 12 Oct 2007 22:58:46 +0200
Vincent Snijders <[EMAIL PROTECTED]> wrote:

> Marc Santhoff schreef:
> > Hi,
> > 
> > the reference manual is not explicitly clear in describing class
> > declarations. Is it true for classes as for objects that the first
> > block of components after the class header are visible as if
> > declared public?
> > 
> > E.g.
> > 
> > TAnyClass = class
> > fField:anytype;
> > end;
> > 
> > would make fField visible "public"?
> 
> It would be "published".

Classes with RTTI information use published, otherwise public.
See the {$M+} switch, for example TPersistent.


> > 
> > And one other question:
> > Does object pascal allow a class declaration marked as an abstract
> > class? Like in java for making sure the class can never be
> > instantiated itself, only it's descendants can be?
> > 
> > Smth. like:
> > 
> > TAnyClass = abstract class(...)
> >  ...
> > end;
> 
> 
> AFAIK, not.

No.
Just add abstract methods and you will get compiler warnings when
instantiating such a class.


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


Re: [fpc-pascal] Specifying a Interface type via $Interfaces

2007-10-12 Thread Joao Morais

Dean Zobec wrote:

As for reference counting - that just means that as soon as the
reference count for an Interfaces reaches zero, it gets automatically
freed?

yes, though you have to pay much attention to memory leaks and
possible problems when dealing a lot with interfaces, memory leaks
should be monitored closely.


An special attention with circular references, ie, one interface whose 
instance holds a reference to another interface whose instance ... holds 
a reference to the first one. The result is an island of leaked objects. 
There are afaik three ways to solve this problem: garbage collection, an 
algorithm to detect the island or one weak reference in order to break 
the chain.


--
Joao Morais

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


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Joao Morais

Felipe Monteiro de Carvalho wrote:

On 10/12/07, Marc Santhoff <[EMAIL PROTECTED]> wrote:

Does object pascal allow a class declaration marked as an abstract
class? Like in java for making sure the class can never be instantiated
itself, only it's descendants can be?


The compiler will issue a warning if you instantiate a class with
abstract methods


Only if creating an instance straight from the class, eg:

This will warn:

begin
  VMyObj := TMyAbstract.Create;

This wont:

var
  VMyClass: TMyAbstractClass;
begin
  VMyClass := TMyAbstract;
  VMyObj := VMyClass.Create;

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


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Joao Morais

Vincent Snijders wrote:

Marc Santhoff schreef:

Hi,

the reference manual is not explicitly clear in describing class
declarations. Is it true for classes as for objects that the first block
of components after the class header are visible as if declared public?

E.g.

TAnyClass = class
fField:anytype;
end;

would make fField visible "public"?


It would be "published".


iirc only if the class or a superclass is declared with $M+

--
Joao Morais

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


Re: [fpc-pascal] fpwrite buffers issues

2007-10-12 Thread ik
On 10/12/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:
> ik schreef:
> > Hi Sorry for the delay in responding
> >
>
> Some remarks at first glance:
> for m := 0 to readcount do
> Should be:
> for m := 0 to readcount-1 do
>
> It would better to use either cshort or smallint.

Thanks that solve most of the problems. Back to learn the new issues
that I found :)

>
> I think fpread and fpwrite expect sizes in bytes and not in cshorts (or is a 
> cshort
> 1 byte).

It's ssize_t and it's longint type...

>
> Vincent

Thank you for the help

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


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Mattias Gaertner
On Fri, 12 Oct 2007 18:41:19 -0300
Joao Morais <[EMAIL PROTECTED]> wrote:

> Felipe Monteiro de Carvalho wrote:
> > On 10/12/07, Marc Santhoff <[EMAIL PROTECTED]> wrote:
> >> Does object pascal allow a class declaration marked as an abstract
> >> class? Like in java for making sure the class can never be
> >> instantiated itself, only it's descendants can be?
> > 
> > The compiler will issue a warning if you instantiate a class with
> > abstract methods
> 
> Only if creating an instance straight from the class, eg:
> 
> This will warn:
> 
> begin
>VMyObj := TMyAbstract.Create;
> 
> This wont:
> 
> var
>VMyClass: TMyAbstractClass;
> begin
>VMyClass := TMyAbstract;
>VMyObj := VMyClass.Create;

Correct. The compiler can only warn about compile time errors, not
runtime errors.
For runtime you can use

constructor TMyAbstract.Create;
begin
  if ClassType=TMyAbstract then raise Exception.Create('abstract
class');
  inherited Create;
end;


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


Re: [fpc-pascal] class declaration questions

2007-10-12 Thread Marc Santhoff
Am Samstag, den 13.10.2007, 00:50 +0200 schrieb Mattias Gaertner:
> On Fri, 12 Oct 2007 18:41:19 -0300
> Joao Morais <[EMAIL PROTECTED]> wrote:
> 
> > Felipe Monteiro de Carvalho wrote:
> > > On 10/12/07, Marc Santhoff <[EMAIL PROTECTED]> wrote:
> > >> Does object pascal allow a class declaration marked as an abstract
> > >> class? Like in java for making sure the class can never be
> > >> instantiated itself, only it's descendants can be?
> > > 
> > > The compiler will issue a warning if you instantiate a class with
> > > abstract methods
> > 
> > Only if creating an instance straight from the class, eg:
> > 
> > This will warn:
> > 
> > begin
> >VMyObj := TMyAbstract.Create;
> > 
> > This wont:
> > 
> > var
> >VMyClass: TMyAbstractClass;
> > begin
> >VMyClass := TMyAbstract;
> >VMyObj := VMyClass.Create;
> 
> Correct. The compiler can only warn about compile time errors, not
> runtime errors.
> For runtime you can use
> 
> constructor TMyAbstract.Create;
> begin
>   if ClassType=TMyAbstract then raise Exception.Create('abstract
> class');
>   inherited Create;
> end;

Very nice, exactly what I need in the situation right now. Although a
compiler switch for telling fpc to bark and stop on error when
instantiating abtract classes would be nice I can live with this
solution very well. :)

Thanks for this one and to anyone helping,
Marc


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