Recent

Author Topic: How to install image library for freepascal on linux?  (Read 9912 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5396
  • My goal: build my own game engine using Lazarus
Re: How to install image library for freepascal on linux?
« Reply #75 on: August 18, 2023, 06:48:37 pm »
Additional, stop using SetBounds() and just activate from image alClient alignment and stretch property.

Originally, I used alClient. You can see it in my very first demo. Unfortunately OP has problem to understand why the loaded image would automatically fit to the screen height and the width and height of the image didn't go as what he thought they should be. I know why but my English is limited I couldn't explain it to him. Instead, I wrote a new demo without set the alignment and use StretchDraw.
https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488538.html#msg488538

Now please advice, how to get 1st argument of program or how to parse arguments.

To read the command line parameters (or what you called arguments), you can use ParamCount and ParamStr command. You can learn how to use it in my very first demo, line #161, #165 and #171:
https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488251.html#msg488251
« Last Edit: August 18, 2023, 06:52:35 pm by Handoko »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #76 on: August 18, 2023, 07:36:32 pm »
Additional, stop using SetBounds() and just activate from image alClient alignment and stretch property.

Originally, I used alClient. You can see it in my very first demo. Unfortunately OP has problem to understand why the loaded image would automatically fit to the screen height and the width and height of the image didn't go as what he thought they should be. I know why but my English is limited I couldn't explain it to him. Instead, I wrote a new demo without set the alignment and use StretchDraw.
https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488538.html#msg488538

Thanks for reminding. I wanted to ask you if is there anywhere in the component saved current width and height of the displayed image, not the original. I know that we basicely know this value on the begin of the program when we use setbounds.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #77 on: August 18, 2023, 08:00:34 pm »
I admit, I didn't read whole thread about a linux topic :) Sorry Handoko
@barr: If not already said, you have two different things, the component "TImage" wich has its Clientarea and inside you have a "TPicture" container that holds the original image.... so "current width and height of the displayed image, not the original" is a very confusing text to me.
When you talk about the window, than refer to TImage root properties, when you talk about the image itself, refer to TPicture properties.
Scaling stretching etc is done automatic if enabled but the "original" is always "original" (if you was paying attention, that goes to TPicture)

@Handoko, what do you think about my suggestion to simplify that "graphical edit" by using a snapshot and merging it in?
« Last Edit: August 18, 2023, 08:02:50 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #78 on: August 18, 2023, 08:04:45 pm »
Where do you save input parameters in project options?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #79 on: August 18, 2023, 08:18:22 pm »
Where do you save input parameters in project options?
If you mean to simulate command line arguments as parameters, Menu Run -> Run Parameters ... -> Commandline Parameters

As a test, here is a quicky:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   Memo1.Lines.BeginUpdate;
  6.   Memo1.Clear;
  7.   for i := 0 to ParamCount do
  8.     Memo1.Lines.Add(Format('Parameter #%d: %s', [i, ParamStr(i)]));
  9.   Memo1.Lines.EndUpdate;
  10. end;
This will end in whats shown on picture 2
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #80 on: August 18, 2023, 08:32:51 pm »
Thank you. Am I doing something wrong that I cannot see value of
ParamCount
ParamStr(1)

Unfortunately I am unable to switch to English. I tried to enable it but it is still in local language. I installed English. Strange.

So I tried to break and step in ParseParams and then to add a watch through Debug menu but I got identifier not found.
« Last Edit: August 18, 2023, 08:57:37 pm by barracuda »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #81 on: August 18, 2023, 09:05:22 pm »
I do not know what language you are using but "ParamCount" and its "ParamStr" method names are everywhere same AFAIK, it is loaded and filled automagical inside the system unit for global usage.
I attached the above demo, open the "project1.lpi" file, all my settings are stored within this project, run it, what does it show?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #82 on: August 19, 2023, 11:13:58 am »
Regardless ParamStr or ParamCount.
During Debuging step by step, I need to check the value of the result or expression: "length(filePath)" in code:
Code: Pascal  [Select][+][-]
  1. s0:=copy(ParamStr(i),length(filePath),999)
I cannot. In Delphi no problem with this. Here I am trying to set s0 to basename.
Also I tried this:
Code: Pascal  [Select][+][-]
  1. s0:=copy(ParamStr(i),length(filePath))
And doesn't work like I expected that it could return the basename.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to install image library for freepascal on linux?
« Reply #83 on: August 19, 2023, 12:14:50 pm »
ParamStr(0) is always the full qualified string for exemplary "X:\YourPath\YourApp.exe" in Delphi or Lazarus/FreePascal.
We can not mindread.... "filePath" is neither in FreePascal nor in Delphi a default common global, show complete that we understand you.

Maybe you just do not know how to debug step by step?
Maybe you just do not know that you can set watches on values for easier checking?
Maybe you just do not know that there is a ExtractFileName() method that can be freely used?
Maybe you just do not supply full information so nobody can guess what you actual try doing?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #84 on: August 19, 2023, 12:40:34 pm »
Maybe you just do not know how to debug step by step?
I do step by step debugging.

Quote from: KodeZwerg link=topic=64159.msg489037#msg489037
Maybe you just do not know that you can set watches on values for easier checking?
[/quote
I tell, you this does not show the evaluated values of funtions. I can do this in Delphi no problem. But in Lazarus is typical "identifier not found". That's why I don't see result of the length function.

Quote
Maybe you just do not know that there is a ExtractFileName() method that can be freely used?
I looked for basename(). But anyway why to extract information which is already known from the variable?
Code: Pascal  [Select][+][-]
  1. filePath := ExtractFilePath(ParamStr(i));

It's always hard decision for me because I prefer low level programming.

So even with the function ExtractFilename ... this doesn't solve the current problem what I am trying to learn. Using ExtractFilename can be fast solution, which skips the need to learn how to use length function and watch expression during debugging. You can provide alternative solution, but I need to learn that little point anyway to be more indepentent on help of others.

I am almost finished with param parsing so I will show you the code a little bit later. Now waiting for response and have to have a break.

* * *
Note:
I see I need to parse arguments in different way
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ParseParams;
  2. var
  3.   i: Integer;
  4.   Params: array of string;
  5. begin
  6.   if ParamCount <= 0 then Exit;
  7.  
  8.   SetLength(Params, ParamCount);
  9.  
  10.   // copy parameters to dynamic artray
  11.   for i := 1 to ParamCount do
  12.     Params[i - 1] := ParamStr(i);
* * *
And I need to change the way I process arguments.

I will use ChatGPT advice.

You are absolutely correct. In FreePascal and its Run-Time Library (RTL), there is a function that allows you to remove the first element from an array similar to array_shift in PHP. This function is called Delete and is located in the SysUtils unit.

Here's an example of how you can use it:

Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils;
  3.  
  4. procedure TForm1.ParseParams;
  5. var
  6.   i: Integer;
  7.   Params: array of string;
  8. begin
  9.   if ParamCount <= 0 then Exit;
  10.  
  11.   SetLength(Params, ParamCount);
  12.   for i := 1 to ParamCount do
  13.     Params[i - 1] := ParamStr(i);
  14.  
  15.   // Removing the first element from the array
  16.   if Length(Params) > 0 then
  17.     Delete(Params, 0, 1);
  18.  
  19.   // Displaying the remaining elements in the array
  20.   for i := 0 to High(Params) do
  21.     Memo1.Lines.Add('Param ' + IntToStr(i) + ': ' + Params[i]);
  22. end;
  23.  

Yet I would like to call the program repetitively like so:
program name "My 1st Gallery" ... argument list of images... &
program name "My 2nd Gallery" ... next images &
program save "My Saturday Galeries" &
program exit &
// Program exited.
// Galeries saved. Let's read them to view the save images:
program read "My Saturday Galeries" &
program exit &

To add the icons and information to the existing instance of the program running in memory. Because I don't know how technically to solve that I asked of chatGPT, so you please tell me if this code it suggested is not just ton of ballshit:

Code: Pascal  [Select][+][-]
  1. uses
  2.   SysUtils, SyncObjs, Windows;
  3.  
  4. type
  5.   TSharedData = record
  6.     // You can add data here that you want to share between instances
  7.   end;
  8.  
  9. var
  10.   Mutex: TMutex;
  11.   SharedData: ^TSharedData;
  12.   Created: Boolean;
  13.  
  14. procedure InitializeSharedMemory;
  15. begin
  16.   Mutex := TMutex.Create(nil, False, 'MySharedMemoryMutex');
  17.   Mutex.Acquire;
  18.  
  19.   Created := False;
  20.   SharedData := MapViewOfFile(
  21.     CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(TSharedData), 'MySharedMemory'),
  22.     FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TSharedData)
  23.   );
  24.  
  25.   if SharedData = nil then
  26.   begin
  27.     Writeln('Could not create or access shared memory.');
  28.     Exit;
  29.   end;
  30.  
  31.   if GetLastError = ERROR_ALREADY_EXISTS then
  32.     Created := True
  33.   else
  34.     FillChar(SharedData^, SizeOf(TSharedData), 0);
  35.  
  36.   Mutex.Release;
  37. end;
  38.  
  39. procedure SendDataToExistingInstance;
  40. begin
  41.   Mutex.Acquire;
  42.  
  43.   // Here you can update data in the shared memory
  44.   // or send a message to the existing instance
  45.  
  46.   Mutex.Release;
  47. end;
  48.  
  49. begin
  50.   InitializeSharedMemory;
  51.  
  52.   if Created then
  53.   begin
  54.     // This is a new instance, perform normal operations
  55.   end
  56.   else
  57.   begin
  58.     // This is an already existing instance, perform communication
  59.     SendDataToExistingInstance;
  60.   end;
  61.  
  62.   // Release the shared memory and mutex
  63.   UnmapViewOfFile(SharedData);
  64.   Mutex.Free;
  65. end.

* * *

I plan to write ini file to save settings. I think I will include this as a separate unit. See attachment.

« Last Edit: August 21, 2023, 10:50:56 am by barracuda »

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #85 on: April 28, 2024, 02:14:02 pm »
I can see your issue now. Unfortunately I don't know what causes it. My guesses, maybe the font files were damaged or maybe you need to reinstall your Lazarus.

I saw you're using older version of Lazarus installed using your OS software manager. Don't use that. You should use the latest version provided by official Lazarus team, here:
https://sourceforge.net/projects/lazarus/files/

I think before you reinstall the Lazarus, you may need to do a complete Lazarus/FPC removal:
https://forum.lazarus.freepascal.org/index.php/topic,38828.msg265293.html#msg265293

I don't know why you want to use CodeTyphon. I and many users here do not use CodeTyphon, you should ask your CodeTyphon issue on their forum.

Hello, I am on Mint 21.3 (I think it was 1st beta version) now x64 notebook. Can I install FPC and Freelazarus from Repo? It is long time I was using Lazarus so did I forget something?
Code: Pascal  [Select][+][-]
  1. sudo apt install fp-compiler-3.2.2
  2.  

Or should I install newer version?
« Last Edit: April 28, 2024, 02:42:37 pm by barracuda »

Thaddy

  • Hero Member
  • *****
  • Posts: 16633
  • Kallstadt seems a good place to evict Trump to.
Re: How to install image library for freepascal on linux?
« Reply #86 on: April 28, 2024, 02:49:47 pm »
sudo apt update
sudo apt install fpc
sudo apt install lazarus

Will install fpc 3.2 and laz 3.0
But I am sure they don't want the Trumps back...

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #87 on: April 28, 2024, 03:50:40 pm »
It did not help (FPC is OK, Lazarus old version) and I cannot remove it now

Code: Pascal  [Select][+][-]
  1. sudo dpkg -r --force-all lazarus-src-2.2
  2. error: lazarus-src-2.2
  3.  

Code: Pascal  [Select][+][-]
  1. apt remove lazarus-src-2.2
  2. Removing lazarus-src-2.2 (2.2.0+dfsg1-5ubuntu1)
  3. dpkg-divert: error: file namedonot absolute
  4. too many errors
  5.  Sub-process /usr/bin/dpkg returned an error code (1)
  6.  
  7.  
  8.  
« Last Edit: April 28, 2024, 03:53:13 pm by barracuda »

Thaddy

  • Hero Member
  • *****
  • Posts: 16633
  • Kallstadt seems a good place to evict Trump to.
Re: How to install image library for freepascal on linux?
« Reply #88 on: April 28, 2024, 05:13:08 pm »
sudo apt purge lazarus
sudo apt autoremove

Removes lazarus. Strange that mint is behind Debian, though.

You can then build lazarus from source by downloading stable from gitlab and do
make bigide.

You may want to add backports to Mint, then you will get lazarus 3.0 when you do sudo apt install lazarus.
« Last Edit: April 28, 2024, 05:43:36 pm by Thaddy »
But I am sure they don't want the Trumps back...

barracuda

  • Full Member
  • ***
  • Posts: 133
Re: How to install image library for freepascal on linux?
« Reply #89 on: April 28, 2024, 06:54:00 pm »
but all tries to remove/purge/autoremove etc. give the same error code 1, name of do file is not absolute

I try this...

Code: Pascal  [Select][+][-]
  1. sudo apt install --fix-broken lazarus-src-2.2
  2.  

the is the error here not "do" (local lang.) but "to" (English).
https://askubuntu.com/questions/1471839/error-while-removing-package-lazarus-src-2-2-dpkg-divert-error-file-name-to

I was so lucky to remove it using this script by Jim:
Code: Pascal  [Select][+][-]
  1. #!/bin/bash
  2.  
  3. # Get a list of diversions with paths
  4. diversions=$(dpkg-divert --list 'lazarus*')
  5.  
  6. # Split the output into strings
  7. IFS=$'\n'
  8.  
  9. # Passing through each line of output
  10. for line in $diversions; do
  11.   # Extract the path from the line
  12.   path=$(echo "$line" | awk '{print $2}')
  13.  
  14.   # Execute the command with the path substituted
  15.   sudo dpkg-divert --remove --no-rename "$path"
  16.  
  17. #Remove the rest of the garbage
  18. sudo apt-get install -f
  19. sudo apt autoremove
  20.  
  21. done
It's recommended to save it for later use. Removing took two hours of pressing y.
« Last Edit: April 28, 2024, 09:26:38 pm by barracuda »

 

TinyPortal © 2005-2018