View Full Version : Official Delphi SDK Download
ErosOlmi
21-12-2006, 11:24
Please use this new SDK to develop thinBasic modules using Turbo Delphi.
Also download thinCore.dll if not already published as public preview or stable version.
Regards
Eros
ErosOlmi
21-12-2006, 12:49
I've locked down this sticky post because I will use it only to announce new Delphi SDK interface.
Thanks
Eros
Michael Hartlef
07-04-2016, 20:38
Thanks Eros,
is the thincore.dll needed? It is a pretty old one, or?
And why the Delphi postfix in LoadLocalSymbols_Delphi and not just LoadLocalSymbols?
ErosOlmi
08-04-2016, 07:07
is the thincore.dll needed? It is a pretty old one, or?
No
And why the Delphi postfix in LoadLocalSymbols_Delphi and not just LoadLocalSymbols?
To instruct thinCore that that module is developd using Delphi and adapt string parameter passing.
thinCore search for LoadLocalSymbols and if not found search for LoadLocalSymbols_Delphi
Attached the latest Delphi SDK I had in my computer.
Michael Hartlef
08-04-2016, 07:22
Thank you,
is there such a prefix for FreePacal too?
ErosOlmi
08-04-2016, 09:41
Delphi/Pascal is the same for the moment. It was just an experiment because I liked Pascal language.
Also thinCore.pas is just a subset of all possible thinCore exported functions because I was not able to directly manage BSTR strings in Pascal.
But if you find a away to handle BSTR strings without special function conversion, we can use the full set of thinCore functionalities.
Michael Hartlef
08-04-2016, 10:33
From FreePascal 2.4 and up, WideStrings should be compatible with BSTR.
Btw. this topic is closed. :)
ErosOlmi
08-04-2016, 11:11
Thread opened again.
Yes, I know but from my tests, this issue is still a problem and creates a GPF: http://stackoverflow.com/questions/9349530/why-can-a-widestring-not-be-used-as-a-function-return-value-for-interop
Maybe it can be bypassed using a BYREF parameters but in any case we need to develop new special functions in Core for all functions returning a thinBasic String (BSTR).
Michael Hartlef
08-04-2016, 12:57
Did I got it to work? What do you think?
Michael Hartlef
08-04-2016, 12:59
To create the DLL I simple called FPC like this:
..\fpc\2.6.4\bin\i386-win32\fpc.exe -Mdelphi -ve thinbasic_MyFreePascal.pas
Eros,
Thanks reopening the topic.
First, I like to know where do I place all the files in the DelphiDLLTest.zip, or your thinBasic Delphi SDK.zip.
Second, how was Michael able to post a reply after you had closed the topic?
Bill
Michael Hartlef
08-04-2016, 14:19
Second, how was Michael able to post a reply after you had closed the topic?
Because I seem to still have my super mod rights from way back. Eros, you can remove them if you want.
Thanks, Michael. Maybe you can reply to my "First" from above?
Bill
ErosOlmi
08-04-2016, 15:30
Thanks reopening the topic.
First, I like to know where do I place all the files in the DelphiDLLTest.zip, or your thinBasic Delphi SDK.zip.
Second, how was Michael able to post a reply after you had closed the topic?
Bill
You can develop your Pascal module dll in any directory you want.
When you need to test your module inside a thinBasic script you need to place your module dll in the same directory of your script.
thinBasic will try to find it with a precise sequence that is described here: http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?uses.htm
Inside your script, to load your module you need to use one of the following command:
USES ... (if you module is named something like "thinBasic_" followed by your module name
MODULE ... (if your module name has not "thinBasic_" as prefix)
Again see help at http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?uses.htm
Ciao
Eros
ErosOlmi
08-04-2016, 15:34
Did I got it to work? What do you think?
Sorry but not much time now at work. I will check this evening when back home and during the week-end.
But if you succeed ... I will ... kiss on your lips :D
Eros,
I appreciate the replay.
Bill
Michael Hartlef
08-04-2016, 16:05
Sorry Bill, that was an overside from me.
Eros, no kiss needed, i was just playing with. It looks like it will work but as it looks to easy, i am wondering if there could be a catch. You can debug the internals of thinbasic and you will see exactly if the returned string is fine.
ErosOlmi
08-04-2016, 19:39
Eros, no kiss needed, i was just playing with. It looks like it will work but as it looks to easy, i am wondering if there could be a catch. You can debug the internals of thinbasic and you will see exactly if the returned string is fine.
Hi Michael,
I checked your .pas code. I was ready to kiss you but unfortunately not :)
All is working fine in your example because you are using thinCore *Delphi exported functions.
Inside thinCore there are a lot of duplicated functions developed to handle FreePascal/Delphi strings as pointers to strings.
For example when you call "thinBasic_ParseString_Delphi" the internal thinCore function executed is the following:
'------------------------------------------------------------------------------
FUNCTION Eval_StrExp_Delphi ALIAS "thinBasic_ParseString_Delphi" (BYVAL pMem AS DWORD PTR) EXPORT AS DWORD
'------------------------------------------------------------------------------
DIM sResult AS STRING
DIM dLen AS DWORD
DIM pAsciiz AS ASCIIZ PTR
DIM pByte AS BYTE PTR
'---Parse a string expression into a PowerBasic strings
Eval_StrExp(sResult)
'---Now transform into a Delphi string
dLen = Len(sResult)
If dLen = 0& Then Exit Function
@pMem = da_MemAlloc(dLen + 8&)
pByte = @pMem
Poke Dword, pByte + 0&, 0&
Poke Dword, pByte + 4&, dLen '---Lenght of the string buffer
Poke$ pByte + 8&, sResult
@pMem = pByte + 8&
'FUNCTION = STRPTR(sResult)
END FUNCTION
As you can see the BSTR string is copied into a Heap memory buffer and returned as a pointer to it. It takes a lot of time to make all those conversions duplicating the needed memory.
To use native BSTR strings you should create a Pascal module that does not need any of the *Delphi thinCore functions.
And use one of the following exported functions that in PowerBasic are declared as:
'---
' Parse one string expression including possible "(" and ")" before and after the string
' This function is the equavalent of the numeric thinBasic_Parse1Number
Declare Function thinBasic_Parse1String Lib "thinCore.DLL" Alias "thinBasic_Parse1String" () As String
'---
' Parse one string expression. It also returns the numeric representation of the parsed string in case it represents a valid number
Declare Function thinBasic_ParseString Lib "thinCore.DLL" Alias "thinBasic_ParseString" (ByRef sResult As String) As Ext
'---
' Parse one string expression.
Declare Sub thinBasic_ParseStr Lib "thinCore.DLL" Alias "thinBasic_ParseStr" (ByRef sResult As String)
Mainly you need to use the same thinCore exported functions that are used to create a module using PowerBasic using all strings as native BSTR strings.
Hope not to have confused you too much.
Ciao
Eros
Michael Hartlef
08-04-2016, 19:49
I only changed the EXEC_SSS function, didn't touch EXEC_Reverse:
And there I don't use the _DELPHI variants:
//----------------------------------------------------------------------------// Returns the reverse of a specified String
//--
// thinBasic Syntax: s = Reverse(AnyStringExpression)
//----------------------------------------------------------------------------
Function Exec_SSS() : pWideChar; STDCALL;
var wStringToReverse: WideString;
Begin
//---Init To nil To avoid compiler warning about possible undefined Return
Exec_SSS := '';
//---Parse the OPEN parenthesis
If thinBasic_CheckOpenParens = _true Then
Begin
//---Parse the String expression needed To be reversed
thinBasic_ParseString(wStringToReverse);
//---Parse the close parenthesis
If thinBasic_CheckCloseParens = _true Then
Begin
//OK, here we Do the job...
//wStringToReverse := WideString(AnsiReverseString(String(wStringToReverse)));
//...And Return result
Exec_SSS := pWideChar(wStringToReverse);
End;
End;
End;
ErosOlmi
08-04-2016, 21:12
mmmmm seems you got something new to my attention.
I need to study it :read:
I have some doubt on memory release allocate by the pascal function?
Will be able thinCore to release it?
I will make some extreme test and see.
In any case you example is much more close to the solution than all other tests I did in the past.
For the moment, thanks a lot.
ErosOlmi
22-04-2016, 14:28
Just to let you know I didn't forget about this thread.
I really would like to have an SDK for FreePascal but in all my tests, thinBasic BSTR strings passed as WideStrings in FreePascal retain their memory allocated and never release it. WideStrings a re managed by FreePascal heap manager and they are counted strings not really BSTR strings.
I'm still testing in order to find a solution.
I have a possible solution that is to use OLE32 native Sys* functions ( https://msdn.microsoft.com/en-us/library/windows/desktop/ms221105(v=vs.85).aspx ) in FreePascal source code but this would require a lot of work for the programmer developing thinBasic module using FreePascal. Maybe I will wrap some helper functions.
Michael Hartlef
22-04-2016, 15:26
If Helper functions do the trick, then it is at least an alternative!
ReneMiner
23-04-2016, 07:58
... thinBasic BSTR strings passed as WideStrings in FreePascal retain their memory allocated and never release it. WideStrings a re managed by FreePascal heap manager and they are counted strings not really BSTR strings...
so what if you take a stringpointer "sPtr" of freePascal-widestring and do this from a .dll (thinCore?):
Heap_Free( sPtr )