Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
Hey my challenge peeps!!

I was given owner access to https://github.com/1brc after asking to be included on the https://1brc.dev site.
Yeah, I know, owner... Still don't understand why, but it's where we're at, LOL!! :D
Now I'm in a bit of a pickle: I don't have an icon that will represent Object Pascal.
There's many for Delphi, and many for Lazarus, but none for Object Pascal in general.
Can anyone help me on this?

Cheers,
Gus
2
FPC development / Re: what to do if my target MIPS cpu has no FPU
« Last post by Laksen on Today at 12:49:12 am »
Anything involving fpu_libgcc is the wrong path to look for, pretty sure it's just leftovers from long ago. fpu_soft is the right fputype for softfloat stuff.
Same with CPUFPEMU, as far as I remember it's only relevant for cases where you have mixed support or ancient cpus
3
I've used a generic wrapper function utilizing implicit function specializations that can then be used to access any enumerator.
The current version of FPC does not support {$modeswitch implicitfunctionspecialization}.

With code
Code: Pascal  [Select][+][-]
  1. for S in specialize WrapClass<TInverseStringsEnumerator>(SList.GetInverseEnumerator) do
  2.   Writeln(S);
there is a memory leak.

With
Code: Pascal  [Select][+][-]
  1. for S in specialize WrapRecord<TInverseStringsEnumerator>(SList.GetInverseEnumerator) do
  2.   Writeln(S);
not.
4
General / Re: Converting a string/index to upper/lower ...
« Last post by TRon on April 18, 2024, 11:56:37 pm »
Perhaps it is me doing something wrong but I seem to get very confused by your description about the behaviour of jvDBSearchEdit.

I made a simple test project and when executed it is impossible for me to type a character that isn't 'valid' (according to jvDBSearchEdit).

While typing the edit corrects what I write to match the contents of a field, no matter what I try to do (that is unless typing something that does not match (anymore)).

The first attached picture shows user typing m (lowercase, the edit component itself turns it into uppercase and automatically "selects" the rest of the field) and the second is after typing i after the initial m character (also here the component corrects the resulting edit field automatically as well as selects the rest of the characters).

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, DB, SQLDB, SQLite3Conn, Forms, Controls, Graphics, Dialogs,
  9.   DBGrids, StdCtrls, JvDBSearchEdit;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     DataSource1: TDataSource;
  17.     DBGrid1: TDBGrid;
  18.     JvDBSearchEdit1: TJvDBSearchEdit;
  19.     Memo1: TMemo;
  20.     SQLite3Connection1: TSQLite3Connection;
  21.     SQLQuery1: TSQLQuery;
  22.     SQLTransaction1: TSQLTransaction;
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure FormDestroy(Sender: TObject);
  25.     procedure JvDBSearchEdit1Change(Sender: TObject);
  26.   private
  27.     procedure CreateDB;
  28.   public
  29.  
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.lfm}
  38.  
  39. { TForm1 }
  40.  
  41. procedure TForm1.FormCreate(Sender: TObject);
  42. begin
  43.   // Clear/init Memo
  44.   Memo1.Clear;
  45.   Memo1.Lines.Values['Status'] := 'Entering form creation';
  46.  
  47.   // Setup transaction
  48.   SQLTransaction1.Active := false;
  49.   SQLTransaction1.Action := caCommitRetaining;
  50.   SQLTransaction1.DataBase := SQLite3Connection1;
  51.  
  52.   // Setup connection
  53.   SQLite3Connection1.Connected := false;
  54.   SQLite3Connection1.LoginPrompt :=false;
  55.   SQLite3Connection1.DatabaseName := ':memory:';
  56.   SQLite3Connection1.Transaction := SQLTransaction1;
  57.  
  58.   // Setup query
  59.   SQLQuery1.DataBase := SQLite3Connection1;
  60.   SQLQuery1.Transaction := SQLTransaction1;
  61.  
  62.   // Setup dataset
  63.   DataSource1.DataSet := SQLQuery1;
  64.  
  65.   // Setup grid
  66.   DBGrid1.DataSource := DataSource1;
  67.  
  68.   // Setup jvdbsearchedit
  69.   JvDBSearchEdit1.DataSource := DataSource1;
  70.   JvDBSearchEdit1.DataField := 'Name';
  71.  
  72.   // Create the database
  73.   CreateDB;
  74.  
  75.   SQLQuery1.Close;
  76.   SQLQuery1.SQL.Text:= 'select * from DATA';
  77.   SQLQuery1.Open;
  78.  
  79.   Memo1.Lines.Values['RecordCount'] := SQLQuery1.RecordCount.ToString;
  80.   Memo1.Lines.Values['Status'] := 'Leaving form creation';
  81. end;
  82.  
  83. procedure TForm1.FormDestroy(Sender: TObject);
  84. begin
  85.   SQLQuery1.Close;
  86.   SQLTransaction1.Active := False;
  87.   SQLite3Connection1.Connected := False;
  88. end;
  89.  
  90. procedure TForm1.JvDBSearchEdit1Change(Sender: TObject);
  91. begin
  92. //  Memo1.Lines.Values['jvDBSearch.DataResult'] := (Sender as TJvDBSearchEdit).DataResult;
  93.   Memo1.Lines.Values['jvDBSearch.DataResult'] := (Sender as TJvDBSearchEdit).Text;
  94.   Memo1.Lines.Values['Status'] := 'Updated jvDBSearchEdit';
  95. end;
  96.  
  97. procedure TForm1.CreateDB;
  98. const
  99.   ItemNames: array of string =
  100.   (
  101.     'Bill','John','Eliza','george','Melinda',
  102.     'Sunshine','Omega','Alice','Fabio','Alvin',
  103.     'medusa', 'Gary', 'michael'
  104.   );
  105. var
  106.   ItemName: string;
  107. begin
  108.   // Setup a table "DATA" in newyl created database
  109.   SQLite3Connection1.ExecuteDirect
  110.   (
  111.     'CREATE TABLE "DATA"'+
  112.     '(' +
  113.       ' "id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,' +
  114.       ' "Name" Char(128) NOT NULL' +
  115.     ');'
  116.   );
  117.  
  118.   // Populate table
  119.   for ItemName in ItemNames do
  120.   begin
  121.     SQLQuery1.SQL.text := 'INSERT INTO ' + '"DATA"' + '(Name) VALUES (:Name);';
  122.     SQLQuery1.Params.ParamByName('Name').AsString     := ItemName;
  123.     SQLQuery1.ExecSQL;
  124.   end;
  125.  
  126.   // Make database magic happen
  127.   SQLTransaction1.Commit;
  128. end;
  129.  
  130. end.
  131.  
No fancy visual edit of properties, all manual in code. I only placed the components on a form.
5
FPC development / Re: what to do if my target MIPS cpu has no FPU
« Last post by PascalDragon on April 18, 2024, 11:44:18 pm »
Seems like there are some locations that don't handle software floating point correctly for the MIPS CPU. Best look for fpu_soft inside the other code generator backends and try to adjust locations in the MIPS backend in similar ways.
6
FPC development / Re: exclude ALL packages from build
« Last post by PascalDragon on April 18, 2024, 11:33:29 pm »
As a first step it would probably be better to only work with make cycle which will only compile the compiler and the RTL or to build the compiler once and do a make all only inside the rtl directory. Once the RTL works you can try to find out where things break in packages.
7
Graphics / Re: Demoscene The Champs Cracktro
« Last post by KodeZwerg on April 18, 2024, 11:29:50 pm »
Another way for a starfield simulation thingy ...
The stars are not moving, they are blinking to simulate you watching stars.
For my taste, less "stars" are better but tested without any problems up to 50k.
Maybe it be useful for upcoming demos/effects.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   BGLVirtualScreen, BGRAOpenGL;
  10.  
  11. type
  12.   TStar = packed record
  13.     X,
  14.     Y: Integer;
  15.     CurCol: TColor;
  16.   end;
  17.   TStars = array of TStar;
  18.  
  19. type
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     BGLVirtualScreen1: TBGLVirtualScreen;
  25.     Panel1: TPanel;
  26.     Timer1: TTimer;
  27.     procedure BGLVirtualScreen1Redraw(Sender: TObject; BGLContext: TBGLContext);
  28.     procedure BGLVirtualScreen1Resize(Sender: TObject);
  29.     procedure FormShow(Sender: TObject);
  30.     procedure Timer1Timer(Sender: TObject);
  31.   strict private
  32.     FStars: TStars;
  33.     FMaxStars: Integer;
  34.   private
  35.     procedure GenerateStars(const AMaxStars: Integer);
  36.   public
  37.  
  38.   end;
  39.  
  40. var
  41.   Form1: TForm1;
  42.  
  43. implementation
  44.  
  45. {$R *.lfm}
  46.  
  47. { TForm1 }
  48.  
  49. procedure TForm1.FormShow(Sender: TObject);
  50. begin
  51.   Randomize;
  52.   GenerateStars(300); // adjust the stars, lower is better
  53.   Timer1.Interval := 250; // adjust the timer, higher is better
  54. end;
  55.  
  56. procedure TForm1.GenerateStars(const AMaxStars: Integer);
  57. var
  58.   i: Integer;
  59. begin
  60.   SetLength(FStars, AMaxStars);
  61.   FMaxStars := AMaxStars;
  62.   for i := Low(FStars) to High(FStars) do
  63.     begin
  64.       FStars[i].X := Random(BGLVirtualScreen1.Width);
  65.       FStars[i].Y := Random(BGLVirtualScreen1.Height);
  66.       FStars[i].CurCol := RGBToColor(
  67.                    Round(255 + (16 - 255) * Succ(i)),
  68.                    Round(255 + (16 - 255) * Succ(i)),
  69.                    Round(255 + (16 - 255) * Succ(i))
  70.                  );
  71.     end;
  72. end;
  73.  
  74. procedure TForm1.Timer1Timer(Sender: TObject);
  75. begin
  76.   BGLVirtualScreen1.Repaint;
  77. end;
  78.  
  79. procedure TForm1.BGLVirtualScreen1Redraw(Sender: TObject;
  80.   BGLContext: TBGLContext);
  81. var
  82.   i: Integer;
  83. begin
  84.   for i := Low(FStars) to High(FStars) do
  85.     BGLContext.Canvas.FillRect(FStars[i].X, FStars[i].Y, FStars[i].X + Succ(Random(2)), FStars[i].Y + Succ(Random(1)), FStars[i].CurCol);
  86. end;
  87.  
  88. procedure TForm1.BGLVirtualScreen1Resize(Sender: TObject);
  89. begin
  90.   GenerateStars(FMaxStars);
  91. end;
  92.  
  93. end.
8
FPC development / exclude ALL packages from build
« Last post by Key-Real on April 18, 2024, 11:18:43 pm »
is it possible to exclude all packages from a build when I do:

make all CPU_TARGET=mipsel OS_TARGET=ps1


or is the only way to edit each fpmake.pp like this:

P.OSes:=AllOSes-[embedded,msdos,win16,go32v2,nativent,macosclassic,palmos,atari,zxspectrum,msxdos,amstradcpc,sinclairql,wasi,human68k];
9
Ok, I get the idea that for in is a simplistic way to iterate through things however as alpine mentioned, sometimes it’s desirable to iterate in descending order. You can’t use “for ... in” to iterate backwards can you?

If one provides a suitable enumerator one can:

Code: Pascal  [Select][+][-]
  1. program tenumerator;
  2.  
  3. {$mode objfpc}
  4. {$modeswitch advancedrecords}
  5. {$modeswitch implicitfunctionspecialization}
  6.  
  7. uses
  8.   Classes;
  9.  
  10. {$Region type with enumerator}
  11. type
  12.   TInverseStringsEnumerator = class
  13.   private
  14.     FStrings: TStrings;
  15.     FPosition: Integer;
  16.   public
  17.     constructor Create(AStrings: TStrings);
  18.     function GetCurrent: String;
  19.     function MoveNext: Boolean;
  20.     property Current: String read GetCurrent;
  21.   end;
  22.  
  23.   TMyStrings = class(TStringList)
  24.     function GetInverseEnumerator: TInverseStringsEnumerator;
  25.   end;
  26.  
  27. constructor TInverseStringsEnumerator.Create(AStrings: TStrings);
  28. begin
  29.   inherited Create;
  30.   FStrings := AStrings;
  31.   FPosition := AStrings.Count;
  32. end;
  33.  
  34. function TInverseStringsEnumerator.GetCurrent: String;
  35. begin
  36.   Result := FStrings[FPosition];
  37. end;
  38.  
  39. function TInverseStringsEnumerator.MoveNext: Boolean;
  40. begin
  41.   Dec(FPosition);
  42.   Result := FPosition >= 0;
  43. end;
  44.  
  45. function TMyStrings.GetInverseEnumerator: TInverseStringsEnumerator;
  46. begin
  47.   Result := TInverseStringsEnumerator.Create(Self);
  48. end;
  49. {$EndRegion}
  50.  
  51. {$Region enumerator utility}
  52. type
  53.   generic TEnumeratorClassWrapper<T> = class
  54.   private
  55.     fEnum: T;
  56.   public
  57.     constructor Create(aEnum: T);
  58.     destructor Destroy; override;
  59.     function GetEnumerator: T;
  60.   end;
  61.  
  62. constructor TEnumeratorClassWrapper.Create(aEnum: T);
  63. begin
  64.   fEnum := aEnum;
  65. end;
  66.  
  67. destructor TEnumeratorClassWrapper.Destroy;
  68. begin
  69.   fEnum.Free;
  70.   inherited;
  71. end;
  72.  
  73. function TEnumeratorClassWrapper.GetEnumerator: T;
  74. begin
  75.   Result := fEnum;
  76. end;
  77.  
  78. generic function WrapClass<T>(aEnum: T): specialize TEnumeratorClassWrapper<T>;
  79. begin
  80.   Result := specialize TEnumeratorClassWrapper<T>.Create(aEnum);
  81. end;
  82.  
  83. type
  84.   generic TEnumeratorRecordWrapper<T> = record
  85.   private
  86.     fEnum: T;
  87.   public
  88.     constructor Create(aEnum: T);
  89.     function GetEnumerator: T;
  90.   end;
  91.  
  92. constructor TEnumeratorRecordWrapper.Create(aEnum: T);
  93. begin
  94.   fEnum := aEnum;
  95. end;
  96.  
  97. function TEnumeratorRecordWrapper.GetEnumerator: T;
  98. begin
  99.   Result := fEnum;
  100. end;
  101.  
  102. generic function WrapRecord<T>(aEnum: T): specialize TEnumeratorRecordWrapper<T>;
  103. begin
  104.   Result := specialize TEnumeratorRecordWrapper<T>.Create(aEnum);
  105. end;
  106. {$EndRegion}
  107.  
  108. var
  109.   slist: TMyStrings;
  110.   s: String;
  111. begin
  112.   slist := TMyStrings.Create;
  113.   try
  114.     slist.Add('One');
  115.     slist.Add('Two');
  116.     slist.Add('Three');
  117.  
  118.     Writeln('In order:');
  119.     for s in slist do
  120.       Writeln(s);
  121.  
  122.     Writeln;
  123.     Writeln('Reverse:');
  124.     for s in WrapClass(slist.GetInverseEnumerator) do
  125.       Writeln(s);
  126.   finally
  127.     slist.Free;
  128.   end;
  129. end.

The assumption is that TMyStrings is a type that provides both an ordinary enumerator (provided by TStrings.GetEnumerator) and a reverse iterator (provided by TMyStrings.GetInverseEnumerator). Due to how enumerators work (the compiler looks for a GetEnumerator method in the type or for a suitable Enumerator operator overload) I've used a generic wrapper function utilizing implicit function specializations (thus WrapClass() instead of specialize WrapClass<TInverseStringEnumerator>()) that can then be used to access any enumerator (one only needs to differentiate between whether the enumerator is a class or a record/interface).

So it's relatively few code that needs to be written every time.
10
Graphics / Re: Demoscene The Champs Cracktro
« Last post by Gigatron on April 18, 2024, 11:03:40 pm »
Hi,

I must just code bitmapfont scroller and it'ok  ;

Pages: [1] 2 3 ... 10

TinyPortal © 2005-2018