Recent

Author Topic: [SOLVED] const char** in FPC?  (Read 643 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
[SOLVED] const char** in FPC?
« on: March 17, 2025, 10:19:38 pm »
got this:

Code: C  [Select][+][-]
  1. typedef struct ACameraIdList {
  2.     int numCameras;          ///< Number of camera device Ids
  3.     const char** cameraIds;  ///< list of camera device Ids
  4. } ACameraIdList;
  5.  

pls help to translate this into pascal
« Last Edit: March 18, 2025, 12:06:04 am by Key-Real »

cdbc

  • Hero Member
  • *****
  • Posts: 2111
    • http://www.cdbc.dk
Re: const char** in FPC?
« Reply #1 on: March 17, 2025, 10:27:47 pm »
Hi
This:
Code: Pascal  [Select][+][-]
  1. char**  == C
  2. PPChar = Pascal
It points to an array of pchars, you could say, that 'char**' is the C equivalent to Pascal's 'TStringArray' ~ a dynamic array of strings
added a couple of minutes later...
Code: Pascal  [Select][+][-]
  1. type
  2.   TCameraIdList = record
  3.     NumCameras: cint; // from c-types unit
  4.     CameraIds: ppchar; // we have that in pascal too
  5.   end;
  6.  
Regards Benny
« Last Edit: March 17, 2025, 10:34:52 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
Re: const char** in FPC?
« Reply #2 on: March 17, 2025, 10:29:31 pm »
how to access it?

Code: Pascal  [Select][+][-]
  1. writeln(camera^.cameraIds[0]^);
  2.  

?

cdbc

  • Hero Member
  • *****
  • Posts: 2111
    • http://www.cdbc.dk
Re: const char** in FPC?
« Reply #3 on: March 17, 2025, 10:37:59 pm »
Hi
Code: Pascal  [Select][+][-]
  1. writeln(camera^.cameraIds[0]^);
will get you the pointer, you'll need to:
Code: Pascal  [Select][+][-]
  1. writeln(camera^.cameraIds[0]^^);
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
Re: const char** in FPC?
« Reply #4 on: March 17, 2025, 10:42:46 pm »
have now:

Code: Pascal  [Select][+][-]
  1. ACameraIdList = record
  2.         numCameras : longint;          ///< Number of camera device Ids
  3.         cameraIds : PPChar;           ///< list of camera device Ids
  4. end;
  5.  

Code: Pascal  [Select][+][-]
  1. ...  string(camera^.cameraIds[0]^^)  <--  Error: Illegal qualifier
  2.  

cdbc

  • Hero Member
  • *****
  • Posts: 2111
    • http://www.cdbc.dk
Re: const char** in FPC?
« Reply #5 on: March 17, 2025, 10:52:08 pm »
Hi
Could it be, that it's:
Code: Pascal  [Select][+][-]
  1. camera^.cameraIds^[0]^
I must admit, I'm a bit rusty in that ol' C, been a looong while...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
Re: const char** in FPC?
« Reply #6 on: March 17, 2025, 10:54:16 pm »
Error: Illegal qualifier

cdbc

  • Hero Member
  • *****
  • Posts: 2111
    • http://www.cdbc.dk
Re: const char** in FPC?
« Reply #7 on: March 17, 2025, 11:15:44 pm »
Hi
I guess trial 'n error is called for...
It's late night here, so I can write a small check-app in the morning, at the earliest...
Maybe google knows how to access it?!? I think there are some examples of use in the 'typinfo' rtl-unit, one could look in there...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

440bx

  • Hero Member
  • *****
  • Posts: 5188
Re: const char** in FPC?
« Reply #8 on: March 17, 2025, 11:18:12 pm »
The cameraIds is a pointer to an array of pointers to null terminated character arrays (C strings.)

Here is an example in Pascal of how to declare that:
Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   Names : array[0..1] of pchar = ('Name1', 'Name2');
  4.  
  5.   ACameraList : record
  6.     CameraCount : integer;
  7.     CameraList  : ^pchar;
  8.   end = (CameraCount:5;CameraList:@Names[0]);
  9.  
  10.   { accessing the above }
  11.  
  12. begin
  13.   { the way it would be done in C }
  14.  
  15.   p := ACameraList.CameraList^;
  16.   p := (ACameraList.CameraList + 1)^;
  17.  
  18.   { the way it's normally done in Pascal }
  19.  
  20.   p := ACameraList.CameraList[0];
  21.   p := ACameraList.CameraList[1];  { <- note the index is (cameraCount - 1) since there are two cameras) }
  22. end.
  23.  
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
Re: const char** in FPC?
« Reply #9 on: March 18, 2025, 12:05:50 am »
yes, thx, this works now :)

440bx

  • Hero Member
  • *****
  • Posts: 5188
Re: const char** in FPC?
« Reply #10 on: March 18, 2025, 06:34:42 am »
yes, thx, this works now :)
You're welcome.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018