Recent

Author Topic: A quick question about library and shortstrings  (Read 708 times)

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
A quick question about library and shortstrings
« on: September 24, 2022, 11:24:03 am »
Hi
Instead of using pchars in library funcrions, is it possible to use shortstrings e.g.
Code: Pascal  [Select][+][-]
  1. type
  2.   TStr80 = string[80];
  3. ...
  4.  
  5. 1) Function libGetVersion(hObj: ptruint): pchar; cdecl; // works fine
  6. 2) Function libGetVersion(hObj: ptruint): shortstring; cdecl; // ?!?
  7. 3) Function libGetVersion(hObj: ptruint): TStr80; cdecl; // ?!?
  8.  
Would 2 or 3 be ok?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

Thaddy

  • Hero Member
  • *****
  • Posts: 18344
  • Here stood a man who saw the Elbe and jumped it.
Re: A quick question about library and shortstrings
« Reply #1 on: September 24, 2022, 11:29:40 am »
1. works fine for string[255]
Anyway it is better to use Pchar, unless you know for sure the library is Pascal and you use it ONLY from Pascal.
And make sure you do not rely on Pascal's memory management.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12531
  • FPC developer.
Re: A quick question about library and shortstrings
« Reply #2 on: September 24, 2022, 11:53:39 am »
If the other side can be made to understand it, then yes. shortstring is a normal static type like a fixed array.

shortstring without [] is equal to shortstring[255]

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
Re: A quick question about library and shortstrings
« Reply #3 on: September 24, 2022, 12:48:28 pm »
Hi
Thank you both  :)
I'm in control of both the library(*.so) and the app... I was just curious  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12531
  • FPC developer.
Re: A quick question about library and shortstrings
« Reply #4 on: September 24, 2022, 01:24:36 pm »
Note that the problem with shortstrings is obviously the length limitation.

 

TinyPortal © 2005-2018