[fpc-pascal] Class type to package name?

2017-07-20 Thread Anthony Walter
Assuming the class type has been registered either through
RegisterComponent or RegisterNoIcon, what is the most straight forward way
to get the package name it is defined in given a class type?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Static local variables available?

2017-07-20 Thread Sven Barth via fpc-pascal
Am 20.07.2017 13:01 schrieb "Bo Berglund" :
>
> On Thu, 20 Jul 2017 11:11:50 +0200, Maciej Izak
>  wrote:
>
> >2017-07-20 11:03 GMT+02:00 Bo Berglund :
> >
> >> So since I don't really want to use a global, is it possible to
> >> declare a local variable static in the sense that it retains its
> >> values across calls to the procedure?
> >> If so how is it done?
> >>
> >
> >procedure foo;
> >{$PUSH}
> >const{$J+}
> >  s : string ='';
> >{$POP}
>
> Thanks,
> but it looks a bit involved, probably better to use an object field
> variable instead only accessible from the internal methods.

If you don't want to use $push/$pop then you can also simply enable $J+ for
the whole unit. But this will also mean that global constants are writable.

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

Re: [fpc-pascal] Implementing AggPas with PtcGraph

2017-07-20 Thread james
I've been having very good results with the accelerated putimage() in ptcgraph. 
   I am wondering if this modification could be added to 3.04, or some future 
release,  as I think everyone would want putimage() to happen as fast as 
possible.I can't figure out how or where to submit this though.   I got the 
original code from here: https://sourceforge.net/p/ptcpas/code/785/tree/trunk/  
and  the code modified code I have is here: 
https://github.com/Zaaphod/ptcpas/tree/Avoid_ReChecking_Bitblt.   I don't see 
any method to submit something similar to a pull request though.   Is there 
some method to contribute code to the PTCPAS project?  

I am also wondering if it would be beneficial to accelerate other procedures in 
the same way especially getimage()   I'm wanting to make it appear as it an 
object moves across the screen so I want to getimage() a small portion of the 
screen, copy the image variable, draw the object in the copy, putimage() the 
copy to show the object, then when it's time to move it, putimage() the 
original back, then start the process over again in the next location.

James

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

Re: [fpc-pascal] Static local variables available?

2017-07-20 Thread Bo Berglund
On Thu, 20 Jul 2017 11:11:50 +0200, Maciej Izak
 wrote:

>2017-07-20 11:03 GMT+02:00 Bo Berglund :
>
>> So since I don't really want to use a global, is it possible to
>> declare a local variable static in the sense that it retains its
>> values across calls to the procedure?
>> If so how is it done?
>>
>
>procedure foo;
>{$PUSH}
>const{$J+}
>  s : string ='';
>{$POP}

Thanks,
but it looks a bit involved, probably better to use an object field
variable instead only accessible from the internal methods.


-- 
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] Subclassing generic records?

2017-07-20 Thread Sven Barth via fpc-pascal
On 17.07.2017 19:20, Ryan Joseph wrote:
> 
>> On Jul 17, 2017, at 10:58 AM, Sven Barth via fpc-pascal 
>>  wrote:
>>
>> I'll need to check whether Delphi allows that for helpers (doesn't matter 
>> whether the extended type is a specialization or not).
>>
>>
> 
> Thanks Sven. Records/objects/classes in Pascal feel very confused right now. 
> Records are moving in the direction of legacy style “objects” which are 
> allocated on the stack so I wonder why objects just don’t replace records 
> already? Having said that why don’t classes just replace records/objects 
> except they allocate on the stack? These 3 distinct constructs don’t really 
> make sense more imo.

First of records can't replace objects, because objects have inheritance
and a VMT for virtual methods not to mention destructors. Secondly this
would lead to all kind of backwards compatibility problems.
Classes are not designed to be allocated on the stack. They are only on
the heap, thus they are a different kind of beast to records and objects.
And records - unlike objects and classes - can have operator overloads
*inside* of them which allows this operators to be used inside generic
specializations.

I have also another solution for your original problem. Take this code:

=== code begin ===

program trechelpfld;

{$mode objfpc}
{$modeswitch advancedrecords}

type
  TTest = record
x, y: Double;
  end;

  TTestHelper = record helper for TTest
  private
function GetWidth: Double; inline;
function GetHeight: Double; inline;
procedure SetWidth(aValue: Double); inline;
procedure SetHeight(aValue: Double); inline;
  public
property Width: Double read GetWidth write SetWidth;
property Height: Double read GetHeight write SetHeight;
  end;

function TTestHelper.GetWidth: Double;
begin
  Result := x;
end;

function TTestHelper.GetHeight: Double;
begin
  Result := y;
end;

procedure TTestHelper.SetWidth(aValue: Double);
begin
  x := aValue;
end;

procedure TTestHelper.SetHeight(aValue: Double);
begin
  y := aValue;
end;

var
  t: TTest;
  x, y: Double;
begin
  t.x := 42.0;
  t.y := 21.0;

  x := t.Width;
  y := t.Height;

  t.Width := y;
  t.Height := x;
end.

=== code end ===

Through the use of "inline" this results in code without calls as the
assembly output of the main procedure without any optimizations shows:

=== code begin ===

.section .text.n_main
.balign 16,0x90
.globl  PASCALMAIN
.type   PASCALMAIN,@function
PASCALMAIN:
.globl  main
.type   main,@function
main:
.Lc21:
# Temps allocated between rbp-16 and rbp+0
# [45] begin
pushq   %rbp
.Lc23:
.Lc24:
movq%rsp,%rbp
.Lc25:
leaq-16(%rsp),%rsp
callFPC_INITIALIZEUNITS
# [46] t.x := 42.0;
movq_$TRECHELPFLD$_Ld1,%rax
movq%rax,U_$P$TRECHELPFLD_$$_T
# [47] t.y := 21.0;
movq_$TRECHELPFLD$_Ld2,%rax
movq%rax,U_$P$TRECHELPFLD_$$_T+8
# [49] x := t.Width;
movsd   U_$P$TRECHELPFLD_$$_T,%xmm0
movsd   %xmm0,U_$P$TRECHELPFLD_$$_X
# [50] y := t.Height;
movsd   U_$P$TRECHELPFLD_$$_T+8,%xmm0
movsd   %xmm0,U_$P$TRECHELPFLD_$$_Y
# [52] t.Width := y;
movqU_$P$TRECHELPFLD_$$_Y,%rax
movq%rax,U_$P$TRECHELPFLD_$$_T
# [53] t.Height := x;
movqU_$P$TRECHELPFLD_$$_X,%rax
movq%rax,U_$P$TRECHELPFLD_$$_T+8
# [54] end.
callFPC_DO_EXIT
leave
ret
.Lc22:
.Le4:
.size   main, .Le4 - main

=== code end ===

It might be more to write, but it works...

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

[fpc-pascal] OS/2 support and text colors

2017-07-20 Thread Graeme Geldenhuys

Hi,

Not strictly FPC related, but I know here are some OS/2 software 
developers around - and I have no idea where else to ask.


I'm working on supporting OS/2 in fpGUI Toolkit and creating OS/2 
themes.  Looking at some of the OS/2 screenshots I have collected, I 
noticed that in the same dialog you sometimes have blue text and 
sometimes black text. Anybody know why, and what is the difference 
between the two (other than the color alone)?


Here is an example:

  http://geldenhuys.co.uk/~graemeg/os2_screenshot.png


The only pattern I can see is that "static text" (eg: labels and 
groupbox captions) use the blue text, but Checkboxes, Buttons, Menu 
Items etc use the black text. I still don't understand IBM's reasoning 
behind this though - but would like to know out of curiosity.


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] Static local variables available?

2017-07-20 Thread Sven Barth via fpc-pascal
On 20.07.2017 11:11, Maciej Izak wrote:
> 2017-07-20 11:03 GMT+02:00 Bo Berglund  >:
> 
> So since I don't really want to use a global, is it possible to
> declare a local variable static in the sense that it retains its
> values across calls to the procedure?
> If so how is it done?
> 
> 
> procedure foo;
> {$PUSH}
> const{$J+}
>   s : string ='';
> {$POP}
> begin
>   writeln(s);
>   if s = '' then
> s := 'hello from static local variable';
> end;
> 
> begin
>   foo; // will print empty line
>   foo; // will print 'hello from static local variable'
>   foo; // will print 'hello from static local variable'
> end.

For completeness sake:
https://www.freepascal.org/docs-html/current/ref/refse10.html#x22-210002.2
, especially the remark at the end.

Regards,
Sven

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

Re: [fpc-pascal] Static local variables available?

2017-07-20 Thread Maciej Izak
2017-07-20 11:03 GMT+02:00 Bo Berglund :

> So since I don't really want to use a global, is it possible to
> declare a local variable static in the sense that it retains its
> values across calls to the procedure?
> If so how is it done?
>

procedure foo;
{$PUSH}
const{$J+}
  s : string ='';
{$POP}
begin
  writeln(s);
  if s = '' then
s := 'hello from static local variable';
end;

begin
  foo; // will print empty line
  foo; // will print 'hello from static local variable'
  foo; // will print 'hello from static local variable'
end.

-- 
Best regards,
Maciej Izak
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Static local variables available?

2017-07-20 Thread Bo Berglund
I am trying to clean up an existing application where handling of
incoming serial data is done inside an event function OnRxData() of
the serial component.
I want to move the processing into a regular procedure so I can later
add a different hardware channel (TCP/IP) as a user choice.

Now when looking at the existing code in the RxData() procedure I see
that there is a while loop retrieving one character at a time from the
serial port and processing it. In the processing these characters are
stuffed into a temp string buffer until the complete packet is ready.

If I divide the single procedure into two where the event procedure
would have the while loop extracting the character and then call a
handling procedure with the char as argument then the processor cannot
have the while, but it must have the buffer...

The only way I could imagine this to work is if:
1) I use a globally defined string variable as buffer
2) It is somehow possible to define the buffer as a static local var.

So since I don't really want to use a global, is it possible to
declare a local variable static in the sense that it retains its
values across calls to the procedure?
If so how is it done?

-- 
Bo Berglund
Developer in Sweden

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