Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
A quick question about library and shortstrings
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Help with search and repa...
by
Zvoni
[
Today
at 05:31:00 pm]
Valgrind stops showing li...
by
Martin_fr
[
Today
at 04:55:56 pm]
[SOLVED] Feature request:...
by
n7800
[
Today
at 03:50:56 pm]
Postgres, ZEOS and Visual...
by
calebs
[
Today
at 03:21:27 pm]
TPairSplitterSide cannot ...
by
CM630
[
Today
at 02:52:37 pm]
AArch64. Slow program sta...
by
Thaddy
[
Today
at 01:27:02 pm]
Porting PDF Viewer from D...
by
domasz
[
Today
at 11:43:17 am]
Variable "xyz" doesn't no...
by
Thaddy
[
Today
at 10:37:26 am]
ATSyntEdit dependency fai...
by
AlexTP
[
Today
at 10:08:55 am]
Anyone interested in help...
by
ad1mt
[
Today
at 09:59:03 am]
Heap Overflow with millio...
by
Martin_fr
[
Today
at 09:04:58 am]
updated pc but.. worse
by
Thaddy
[
Today
at 06:11:57 am]
Lazarus Bugfix Release 4...
by
n7800
[
Today
at 12:34:13 am]
Fpcupdeluxe
by
Josh
[
Today
at 12:01:05 am]
Getting a true variant pa...
by
440bx
[November 11, 2025, 11:41:22 pm]
Problem Installing CHM He...
by
marcov
[November 11, 2025, 10:35:25 pm]
jBitmap rotation
by
neuro
[November 11, 2025, 10:01:43 pm]
Google Play Store require...
by
nobody.00
[November 11, 2025, 07:34:30 pm]
Bindings for PlutoVG
by
CynicRus
[November 11, 2025, 04:49:28 pm]
Lazarus 4.4 documentation...
by
dsiders
[November 11, 2025, 04:13:58 pm]
Creating a fully cross pl...
by
Thaddy
[November 11, 2025, 03:51:55 pm]
UnoLib - library in Pasca...
by
ackarwow
[November 11, 2025, 01:06:58 pm]
Lazarus caught AV, seems ...
by
Martin_fr
[November 11, 2025, 12:20:47 pm]
application crashes on st...
by
Thaddy
[November 11, 2025, 08:30:33 am]
synedit
by
scasparz
[November 11, 2025, 08:21:38 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: A quick question about library and shortstrings (Read 708 times)
cdbc
Hero Member
Posts: 2466
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]
[+]
[-]
type
TStr80
=
string
[
80
]
;
...
1
)
Function
libGetVersion
(
hObj
:
ptruint
)
:
pchar
;
cdecl
;
// works fine
2
)
Function
libGetVersion
(
hObj
:
ptruint
)
:
shortstring
;
cdecl
;
// ?!?
3
)
Function
libGetVersion
(
hObj
:
ptruint
)
:
TStr80
;
cdecl
;
// ?!?
Would 2 or 3 be ok?
Regards Benny
Logged
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.
Logged
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]
Logged
cdbc
Hero Member
Posts: 2466
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
Regards Benny
Logged
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.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
A quick question about library and shortstrings
TinyPortal
© 2005-2018