[fpc-pascal] How to declare function with untyped array parameter

2016-05-25 Thread LacaK

Hi,

is there way how to declare function, which will accept as parameter any 
array type ?

(this parameter I need forward to System.Length() only )

Just like Length() function.

Now I fall into problem with generics , where I have in one unit generic 
object, which has Length property (or Length function)

This function internally calls System.Length(A)

But when I specialize such generic in another unit, I give "Compilation 
aborted" (FPC 2.6.4)


Culprit is prefix "System.".

When I omit prefix "System." then I give another error: Wrong number of 
parameters specified for call to "Length"

(compiler is probably recognizing "Length" of object )

Example:

-

1st unit:

  generic GT = object
private
  var
FArray: array of T;
Fx, Fy: integer;
  function GetLength: integer;
public
  type
TElement = T;
PElement = ^T;
  constructor Init; overload;
  constructor Init(x,y: integer); overload;
  property Length: integer read GetLength;
  end;

function T2DArray.GetLength: integer;
begin
  Result := System.Length(FArray);   // <-- HERE prefix System is 
causing "Compilation aborted" in FPC 2.6.4

end;

-

2nd unit:

T2DIntArray = object(specialize GT) end;

-

Is there any workaround ?

Thanks

L.

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


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Bo Berglund
On Wed, 25 May 2016 21:59:21 +0100, Graeme Geldenhuys
 wrote:

>On 2016-05-25 15:58, Paul Breneman wrote:
>> so 
>> if you can figure out what part to use it should work good in Delphi and 
>> FPC.
>
>I can confirm Abbrevia worked well for a Delphi/FPC project I worked on
>a couple years ago. I also don't recall it being difficult to use.
>

OK, I will see if I can work with it without installing the complete
package. Maybe I can just figure out the needed units and go with
these. If so I will post the result here (I mean which units were
needed for a minimum file write).


-- 
Bo Berglund
Developer in Sweden

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


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Graeme Geldenhuys
On 2016-05-25 15:58, Paul Breneman wrote:
> so 
> if you can figure out what part to use it should work good in Delphi and 
> FPC.

I can confirm Abbrevia worked well for a Delphi/FPC project I worked on
a couple years ago. I also don't recall it being difficult to use.

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Paul Breneman

On 05/25/2016 09:56 AM, Bo Berglund wrote:

On Wed, 25 May 2016 08:21:54 -0500, Paul Breneman
 wrote:


You've probably considered Abbrevia:
http://wiki.lazarus.freepascal.org/FreePascalArchivePackage


Yes,
I got that as a suggestion over at the Embarcadero forum...

But when I downloaded it from Sourceforge it turned out to be really
massive, some 700+ files and basically overwhelming.

I would like something simple, preferably built-in like TZipFile in
later versions of Delphi. Or paszlib in FPC...
But I also would like to have it work both in Delphi and FPC/Lazarus.



Yes, it may be large as it does a *lot* of things.  I know that people 
invested a *lot* of work in improving it after it went open source, so 
if you can figure out what part to use it should work good in Delphi and 
FPC.


Regards,
Paul
www.ControlPascal.com

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


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Bo Berglund
On Wed, 25 May 2016 08:21:54 -0500, Paul Breneman
 wrote:

>You've probably considered Abbrevia:
>http://wiki.lazarus.freepascal.org/FreePascalArchivePackage
>
Yes,
I got that as a suggestion over at the Embarcadero forum...

But when I downloaded it from Sourceforge it turned out to be really
massive, some 700+ files and basically overwhelming.

I would like something simple, preferably built-in like TZipFile in
later versions of Delphi. Or paszlib in FPC...
But I also would like to have it work both in Delphi and FPC/Lazarus.

-- 
Bo Berglund
Developer in Sweden

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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Jonas Maebe


Michael Van Canneyt wrote on Wed, 25 May 2016:


On Wed, 25 May 2016, Jonas Maebe wrote:


Sven Barth wrote on Wed, 25 May 2016:


An method pointer is always automatically constructed by the compiler
consisting of the address of the method (here IFPReportFilter.RenderReport)
and the instance that method belongs to (in this case the FReportFilter),
so this will indeed work without problems.
The question however is whether it is guaranteed to keep working and isn't
merely the use of an implementation detail...


It works by design. I can't think of a reason why it would stop working.


What is the self in case of an interface that is not in a FPC program ?


In all cases we pass the unadjusted interface pointer. Such an  
interface pointer is always a pointer to an interface VMT  
pointer/address.


The interface method is required to be able to reconstitute the  
interface's self pointer (the start of the instance that implements  
this interface) from that. In both FPC and in regular COM, that  
generally happens by some kind of stub code that is created for every  
interface method implemented by a class, which subtracts the offset of  
the interface's VMT in that specific class' instance layout from the  
passed self pointere.



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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Graeme Geldenhuys
On 2016-05-25 13:31, Sven Barth wrote:
> that contains the pointer to the method as well as what is going to be
> loaded as "Self" (the data part Michael mentioned)

Thanks for explaining it Sven.

Regards,
  Graeme

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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Graeme Geldenhuys
On 2016-05-25 13:32, Jonas Maebe wrote:
> It works by design.

Excellent, thanks for confirming that.


Regards,
  Graeme

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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Michael Van Canneyt



On Wed, 25 May 2016, Jonas Maebe wrote:



Sven Barth wrote on Wed, 25 May 2016:


An method pointer is always automatically constructed by the compiler
consisting of the address of the method (here IFPReportFilter.RenderReport)
and the instance that method belongs to (in this case the FReportFilter),
so this will indeed work without problems.
The question however is whether it is guaranteed to keep working and isn't
merely the use of an implementation detail...


It works by design. I can't think of a reason why it would stop working.


What is the self in case of an interface that is not in a FPC program ?

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


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Paul Breneman

On 05/25/2016 03:00 AM, Bo Berglund wrote:

I have a project that is targeting both Linux (on Raspberry Pi) and
Windows. It started in Delphi 2007 and is a command line utility.

It needs to use some zip compression of binary files, which must be
readable both by the programs and the standard tools (WinZip etc).

I am going to finish the code in Delphi 2007 and then move the files
over to FPC on the RPi and compile there.
So I need a zipper that can be used in both ends and since D2007 does
not come with one built in but FPC does (paszlib), I figured I could
copy the src dir from FPC over to Delphi and use that to compress my
files.

Question before I start:
Does this work or must I add a number of conditionals or such in the
code to make it work?
Also: which files are needed? It looks like the paszlib src dir has a
subdir too with most of the files, is this necessary?


You've probably considered Abbrevia:
http://wiki.lazarus.freepascal.org/FreePascalArchivePackage

Regards,
Paul
www.ControlPascal.com

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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Jonas Maebe


Sven Barth wrote on Wed, 25 May 2016:


An method pointer is always automatically constructed by the compiler
consisting of the address of the method (here IFPReportFilter.RenderReport)
and the instance that method belongs to (in this case the FReportFilter),
so this will indeed work without problems.
The question however is whether it is guaranteed to keep working and isn't
merely the use of an implementation detail...


It works by design. I can't think of a reason why it would stop working.


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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Sven Barth
Am 25.05.2016 13:54 schrieb "Graeme Geldenhuys" <
mailingli...@geldenhuys.co.uk>:
>
> On 2016-05-25 12:18, Michael Van Canneyt wrote:
> > I am not sure this is safe to do, since an event handler exists of 2
> > pointers: data and method. As far as I know, an interface does not have
a
> > data pointer.
>
> I don't fully understand your statement about 2 pointers? An event
> handler is simply a procedure of a object. When an event is triggered,
> that simply means the procedure is called and parameters are passed to it.

A "procedure of object" is in fact a TMethod record (yes that type exists)
that contains the pointer to the method as well as what is going to be
loaded as "Self" (the data part Michael mentioned), because without that
you wouldn't know which instance this method belongs to (all instances of a
class share the same code after all).

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

Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Sven Barth
Am 25.05.2016 13:18 schrieb "Michael Van Canneyt" :
>
>
>
> On Wed, 25 May 2016, Graeme Geldenhuys wrote:
>
>> Hi,
>>
>> Can I safely assign a method from an Interface reference to an event
>> handler. The code below works, but I'm not sure if it is safe to do so,
>> and allowed.
>>
>> ==
>>  TTestApp = class(TObject)
>>  private
>>rpt: TFPReportReport;
>>FReportFilter: IFPReportFilter; // can hold any export filter
>>  ...
>>
>> constructor TTestApp.Create;
>> begin
>>  rpt := TFPReportReport.Create(nil);
>>  rpt.Author := 'Graeme Geldenhuys';
>>  rpt.Title := 'FPReport Demo 4 - Frames and Fonts';
>>
>>  FReportFilter := TFPReportExportPDF.Create;  // PDF output
>>  //FReportFilter := TFPReportExportAggPas.Create;  // PNG output
>>  rpt.OnRenderReport := @FReportFilter.RenderReport;
>>  ...
>> end;
>
>
> I am not sure this is safe to do, since an event handler exists of 2
> pointers: data and method. As far as I know, an interface does not have a
> data pointer.

An method pointer is always automatically constructed by the compiler
consisting of the address of the method (here IFPReportFilter.RenderReport)
and the instance that method belongs to (in this case the FReportFilter),
so this will indeed work without problems.
The question however is whether it is guaranteed to keep working and isn't
merely the use of an implementation detail...

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

Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Bo Berglund
On Wed, 25 May 2016 12:59:34 +0200 (CEST),
mar...@stack.nl (Marco van de Voort) wrote:

>I would look for a ZIP codebase based on top of the zlib stream
>(TCompressionstream) interfaces.
>
>These exist both in Delphi and FPC.

I checked in the D2007 help and it did show the TCompressionstream
class so it does exist in my Delph version.

Next is trying to find a zipper based on that, I guess...
When I google the first hit points to paszlib, so I am in a circle
here. Paszlib wiki doc pages state that paszlib is used for
TCompressionstream...
http://wiki.lazarus.freepascal.org/paszlib  (second line)

>If you don't need the archiving aspect (multiple files into one), and only
>the compression, consider using gzip instead of ZIP, since it opens with
>fairly general tools like winzip, and TCompressionStream is enough.

Well, the system I am working on collects data from a measuring
instrument and saves the binary data (a memory image from the
instrument) onto several types of bin files. Then it also converts the
data to corresponding ASCII text files. Finally it is all stuffed into
a single zipfile for transmission.
SoI need multiple files into one just like WinZip provides. Except
done in my code.


-- 
Bo Berglund
Developer in Sweden

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


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Graeme Geldenhuys
On 2016-05-25 12:18, Michael Van Canneyt wrote:
> I am not sure this is safe to do, since an event handler exists of 2
> pointers: data and method. As far as I know, an interface does not have a
> data pointer.

I don't fully understand your statement about 2 pointers? An event
handler is simply a procedure of a object. When an event is triggered,
that simply means the procedure is called and parameters are passed to it.

So that explains why my code worked - I'm simply calling a method of
that interface. This all works as long as the interface reference stays
in scope of course - which it is in my case

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Michael Van Canneyt



On Wed, 25 May 2016, Graeme Geldenhuys wrote:


Hi,

Can I safely assign a method from an Interface reference to an event
handler. The code below works, but I'm not sure if it is safe to do so,
and allowed.

==
 TTestApp = class(TObject)
 private
   rpt: TFPReportReport;
   FReportFilter: IFPReportFilter; // can hold any export filter
 ...

constructor TTestApp.Create;
begin
 rpt := TFPReportReport.Create(nil);
 rpt.Author := 'Graeme Geldenhuys';
 rpt.Title := 'FPReport Demo 4 - Frames and Fonts';

 FReportFilter := TFPReportExportPDF.Create;  // PDF output
 //FReportFilter := TFPReportExportAggPas.Create;  // PNG output
 rpt.OnRenderReport := @FReportFilter.RenderReport;
 ...
end;


I am not sure this is safe to do, since an event handler exists of 2
pointers: data and method. As far as I know, an interface does not have a
data pointer.

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


Re: [fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Marco van de Voort
In our previous episode, Bo Berglund said:
> over to FPC on the RPi and compile there.
> So I need a zipper that can be used in both ends and since D2007 does
> not come with one built in but FPC does (paszlib), I figured I could
> copy the src dir from FPC over to Delphi and use that to compress my
> files.

paszlib was originally a TP/D1 package that was afaik somewhat adapted to
32-bit delphi too.

FPC integrated this package about 15 years, and compatibility with other
compilers is not guaranteed. The units are compiled in FPC mode, not even in
TP or Delphi mode.
 
> Also: which files are needed? It looks like the paszlib src dir has a
> subdir too with most of the files, is this necessary?

I would look for a ZIP codebase based on top of the zlib stream
(TCompressionstream) interfaces.

These exist both in Delphi and FPC.

If you don't need the archiving aspect (multiple files into one), and only
the compression, consider using gzip instead of ZIP, since it opens with
fairly general tools like winzip, and TCompressionStream is enough.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Assigning Interface method to event handler

2016-05-25 Thread Graeme Geldenhuys
Hi,

Can I safely assign a method from an Interface reference to an event
handler. The code below works, but I'm not sure if it is safe to do so,
and allowed.

==
  TTestApp = class(TObject)
  private
rpt: TFPReportReport;
FReportFilter: IFPReportFilter; // can hold any export filter
  ...

constructor TTestApp.Create;
begin
  rpt := TFPReportReport.Create(nil);
  rpt.Author := 'Graeme Geldenhuys';
  rpt.Title := 'FPReport Demo 4 - Frames and Fonts';

  FReportFilter := TFPReportExportPDF.Create;  // PDF output
  //FReportFilter := TFPReportExportAggPas.Create;  // PNG output
  rpt.OnRenderReport := @FReportFilter.RenderReport;
  ...
end;

destructor TTestApp.Destroy;
begin
  rpt.Free;
  FReportFilter := nil;
  inherited Destroy;
end;
==

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Using paszlib from fpc 3.0 with fpc and delphi 2007?

2016-05-25 Thread Bo Berglund
I have a project that is targeting both Linux (on Raspberry Pi) and
Windows. It started in Delphi 2007 and is a command line utility.

It needs to use some zip compression of binary files, which must be
readable both by the programs and the standard tools (WinZip etc).

I am going to finish the code in Delphi 2007 and then move the files
over to FPC on the RPi and compile there.
So I need a zipper that can be used in both ends and since D2007 does
not come with one built in but FPC does (paszlib), I figured I could
copy the src dir from FPC over to Delphi and use that to compress my
files.

Question before I start:
Does this work or must I add a number of conditionals or such in the
code to make it work?
Also: which files are needed? It looks like the paszlib src dir has a
subdir too with most of the files, is this necessary?


-- 
Bo Berglund
Developer in Sweden

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