Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginners / Re: Never code like this
« Last post by Roland57 on Today at 07:02:06 am »
Having no luck so far.
I can't even get your source to compile

The example uses a modified version of AggPas, but I don't remember how I got that modified version.  :-[

In case you would try it, I put the example with modified AggPas here: aggpas-ptcgraph-example.zip

But even without compiling the example, you could take inspiration from it. The interesting part is how the example uses the PutImage procedure.

and I cannot compile the unit pctgraph
(... Error: Illegal unit name: ptcgraph (expecting PROGRAM))

I don't know how you got that error.

To be sure, can you compile this simple program?

Code: Pascal  [Select][+][-]
  1. program Hello;
  2.  
  3. uses
  4. {$IFDEF unix}
  5.   cThreads,
  6. {$ENDIF}
  7.   ptcCrt, ptcGraph;
  8.  
  9. var
  10.   s: string;
  11.   gd, gm: smallint;
  12.   err: smallint;
  13.  
  14. begin
  15.   gd := VGA;
  16.   gm := VGAHi;
  17.   InitGraph(gd, gm, '');
  18.   SetBkColor(Blue);
  19.   SetColor(Yellow);
  20.   err := GraphResult;
  21.   if err = grOK then
  22.   begin
  23.     s := 'Hello world by ptcGraph';
  24.     OutTextXY(
  25.       (GetMaxX - TextWidth (s)) div 2,
  26.       (GetMaxY - TextHeight(s)) div 2,
  27.       s
  28.     );
  29.     ReadKey;
  30.     CloseGraph;
  31.   end;
  32. end.
  33.  
2
Форум складчина, складчики или складчик позволяет покупать вскладчину инфопродукты. Это как торрент или скачать бесплатно курсы
Source:
 
Форум «Складчина» . Складчик - совместные покупки
 
 
Форум «Складчина» . Складчик - совместные покупки
3
Games / Ray4Laz Examples
« Last post by Guva on Today at 05:32:32 am »
I have created a repository with examples for raylib rewritten in pascal language from third-party developers.
https://github.com/GuvaCode/Ray4LazExample

So far there is only one example rewritten from c++


4
Beginners / Re: trying to create an own component but getting SIGSEGV
« Last post by r.lukasiak on Today at 03:17:57 am »
@HeavyUser thanks for your answer, this is already solved but does you solution have some advantages over Handoko's solution (Btn.OnClick:=@MyButtonClick)?

The Panel with custom drawn transparent background is kinda solved. Since TPanel is transparent on both Windows and Linux, I just put TImage on top of it and custom draw it. However, for learning purposes and better understanding... is it possible to replace TPanel with TImage?

Now I faced another obstacle...

now my class is:
Code: Pascal  [Select][+][-]
  1. Ttest = class(TPanel)
  2.     private
  3.       bkg: TImage;
  4.       title: TLabel;
  5.       btn: TButton;
  6.     public
  7.       MyLabel: string; //this value is supposed to be displayed in Title.Caption, it may be changed on runtime, any time
  8.       constructor Create(AOwner: TComponent);
  9.       procedure ButtonClick(Sender: TObject);
  10.       procedure BkgPaint(Sender: TObject);
  11.   end;

How can I make TLabel.Caption=MyLabel? I mean when I update the value MyTest.MyLabel:='some value', how the TTest may know the value changed and need to update Title (TLabel) ?


----------------------------------------------
UPDATE:

I somehow solved it by adding TTest.SetTitle procedure but is there any way to have the same effect by just MyTest.MyLabel:='...'?
5
Did you look at p-machine implementations at all? P6 is fresh, but first few were built in the seventies when resources were even more limited, so I do not see a problem comming from that side.

Which P6 ?

https://github.com/samiam95124/Pascal-P6     Last commit 4-5 years ago....

http://wirth-dijkstra-langs.org/  Hasn't processed FPC compatibility contributions sent 3 (4?) years ago.

Both seem to be quite stale.

https://sourceforge.net/p/pascal-p6/code/ci/master/tree/

Last change was in 2020
6
Embedded / Re: Setting up Xtensa-FreeRTOS for ESP8266
« Last post by Mongkey on Today at 01:14:12 am »
Thank you ccrause, this one is my following fpc setting
7
Beginners / Re: trying to create an own component but getting SIGSEGV
« Last post by HeavyUser on Today at 12:41:10 am »
@Handoko thanks for the links, great article but I think it's a little bit overwhelming for me, at least for now :D
I was hoping for solution like Btn.OnClick:=@MyButtonClick; and from your code I see it's doable this way. Thanks a lot!
I will take care of the "freeing" issue.
Thanks everyone, it works as I needed.

And what would change if I used TImage instead of TPanel? TImage can't be "a parent", right? I'm trying to use TImage but I can't seem to have my components visible (since I can't assign a parent).
I need something that I can draw with BGRABitmap to have a transparent background. I used TBCPanel on Linux (QT5) but it's not transparent on Windows (for some reason) and I can't figure out how to draw on TPanel with BGRABitmap.
Code: Pascal  [Select][+][-]
  1.  
  2.   { Ttest }
  3.  
  4.   Ttest = class(TPanel)
  5.   private
  6.     title: TLabel;
  7.     btn: TButton;
  8.     function GetButtonClick: TNotifyEvent;
  9.     procedure SetButtonClick(AValue: TNotifyEvent);
  10.   public
  11.     constructor Create(AOwner: TComponent);override;
  12.  
  13.     property ButtonClick : TNotifyEvent read GetButtonClick write SetButtonClick;
  14.   end;
  15.  
  16. function Ttest.GetButtonClick: TNotifyEvent;
  17. begin
  18.   Result := btn.OnClick;
  19. end;
  20.  
  21. procedure Ttest.SetButtonClick(AValue: TNotifyEvent);
  22. begin
  23.   btn.OnClick := AValue;
  24. end;
  25.  
  26. constructor Ttest.Create(AOwner: TComponent);
  27. begin
  28.   inherited;
  29.   Self.Caption:='My Panel';
  30.   title:=TLabel.Create(AOwner);
  31.   title.Parent:=Self;
  32.   title.Align:=alTop;
  33.   title.Caption:='My Label';
  34.   btn:=TButton.Create(AOwner);
  35.   btn.Parent:=Self;
  36.   btn.Align:=alBottom;
  37.   btn.Caption:='My Button';
  38. end;
  39.  
  40.  
here you go you simply assign an onclick even to the ButtonClick property and the button will call it.

PS.
Everything was typed directly on the browser no testing or compilation took place in this example you might have to overcome an error or two.
8
Beginners / Re: Never code like this
« Last post by BobDog on Today at 12:33:26 am »
Thanks Roland.
Having no luck so far.
I can't even get your source to compile

agg_pixfmt_rgb_packed  not found

and I cannot compile the unit pctgraph
(... Error: Illegal unit name: ptcgraph (expecting PROGRAM))
9
General / Re: Strange error with arccos()
« Last post by Paolo on Today at 12:06:46 am »
For who is interested on tanh issue topic

https://gitlab.com/freepascal.org/fpc/source/-/issues/39867
10
General / Is possible to add custom claims to TJWT?
« Last post by LeoBruno on August 17, 2022, 10:41:22 pm »
Hi:

I´m porting an application from Delphi, and with Paolo Rossi JWT implementation is possible to add custom claims.

I took a look into the source and couldn´t figure out how to do it.

For now, I´m using an example found on the internet.

fpc code:

Code: Pascal  [Select][+][-]
  1. function GetJWTToken(aEmail: string): TJsonObject;
  2. var
  3.   _JWTToken: TJWT;
  4.   _HMAC: IHMAC;
  5.   _Agora,
  6.   _DtaExpiracao: TDateTime;
  7.   _Assinatura,
  8.   _Token: string;
  9. begin
  10.   _Agora := TModelServerUtils.GetInstancia.GetServerDateTime;
  11.   _JWTToken := TJWT.Create;
  12.   try
  13.     _JWTToken.JOSE.alg := 'HS512';
  14.     _JWTToken.JOSE.typ := 'JWT';
  15.    // _DtaExpiracao := (_Agora + 1);
  16.  
  17.     _DtaExpiracao := (_Agora + 365);
  18.  
  19.     _JWTToken.Claims.iss := 'TestIssuer';
  20.     _JWTToken.Claims.sub := aEmail;
  21.     _JWTToken.Claims.iat := Trunc(_Agora);
  22.     _JWTToken.Claims.exp := Trunc(_DtaExpiracao);
  23.  
  24.     if (_JWTToken.JOSE.alg = 'HS256') then
  25.       _HMAC := THashFactory.THMAC.CreateHMAC(THashFactory.TCrypto.CreateSHA2_256)
  26.     else if (_JWTToken.JOSE.alg = 'HS384') then
  27.       _HMAC := THashFactory.THMAC.CreateHMAC(THashFactory.TCrypto.CreateSHA2_384)
  28.     else if (_JWTToken.JOSE.alg = 'HS512') then
  29.       _HMAC := THashFactory.THMAC.CreateHMAC(THashFactory.TCrypto.CreateSHA2_512)
  30.     else
  31.       raise Exception.Create('[alg] não implementado');
  32.  
  33.     _HMAC.Key := TConverters.ConvertStringToBytes(UTF8Encode(cSecret), TEncoding.UTF8);
  34.     _Assinatura := HexToAscii(TConverters.ConvertBytesToHexString(_HMAC.ComputeString(UTF8Encode(Trim(_JWTToken.AsString)), TEncoding.UTF8).GetBytes,False));
  35.     _Assinatura := _JWTToken.Base64ToBase64URL(EncodeStringBase64(_Assinatura));
  36.  
  37.     _Token := _JWTToken.AsString + '.' + _Assinatura;
  38.  
  39.     result := TJsonObject.Create;
  40.     result.Add('AcessToken', _Token);
  41.     result.Add('ValidUntil', DateTimeToStr(_DtaExpiracao));
  42.   finally
  43.     _JWTToken.Free;
  44.   end;
  45. end;
  46.  

Delphi code (just mind the setclaimsoftype section:
Code: Pascal  [Select][+][-]
  1. function GetJWTToken(aNumCnpjCpf, aCadCompleto: string): string;
  2. var
  3.   _JWTToken: TJWT;
  4.   _DtaExpiracao: TDateTime;
  5. begin
  6.   _JWTToken := TJWT.Create;
  7.   try
  8.     _DtaExpiracao := (Now + 10);
  9.  
  10.     _JWTToken.Claims.Issuer := 'TestIssuer';
  11.     _JWTToken.Claims.Subject := aNumCnpjCpf;
  12.     _JWTToken.Claims.Expiration := _DtaExpiracao;
  13.     _JWTToken.Claims.IssuedAt := Now;
  14.     _JWTToken.Claims.SetClaimOfType<string>('ind_cadastro_completo', aCadCompleto);
  15.  
  16.     result := TJose.SHA256CompactToken(cSecret, _JWTToken);
  17.   finally
  18.     _JWTToken.Free;
  19.   end;
  20. end;
  21.  

Is it possible to do it?

How?

Thank's in advance...


Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018