Because I seem to still have my super mod rights from way back. Eros, you can remove them if you want.Second, how was Michael able to post a reply after you had closed the topic?
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
Because I seem to still have my super mod rights from way back. Eros, you can remove them if you want.Second, how was Michael able to post a reply after you had closed the topic?
Thanks, Michael. Maybe you can reply to my "First" from above?
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/prod....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/prod....html?uses.htm
Ciao
Eros
Last edited by ErosOlmi; 08-04-2016 at 15:31.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Eros,
I appreciate the replay.
Bill
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.
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:
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.'------------------------------------------------------------------------------ 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
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:
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.'--- ' 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)
Hope not to have confused you too much.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
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;
mmmmm seems you got something new to my attention.
I need to study it
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.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Bookmarks