![]() |
Delphi-Version: 2010
Class with strings in DLL
I have a problem, I need to use class in DLL, this class as normal classes has strings as properties and parameters.
I have global variable (object of class), exported functions uses PChar for strings and works on that global variable. DLL compiles. When I try use any function from it, raises AV. F1 :( |
AW: Class with strings in DLL
U have to use the Unit sharemem (in DLL and Application)
|
AW: Class with strings in DLL
To share
Delphi-Quellcode:
is needed
string
![]() Classes may not be shared, because using the EXE and DLL separate RTTIs. > runtime packages |
Re: Class with strings in DLL
I thought that this unit is required if parameters are string not PChar. This is bad news :( I checked that Borlndmm.dll must be present, this is not acceptable for me, do you know pure Delphi solution (with no additional libs)?
|
AW: Class with strings in DLL
Try the unit "FastMM" instead. If you really use Delphi 2010 it should already be part of the provided units.
It's a solution without another DLL, but you need to use that memory manager in the DLL and the EXE. If you need to interface with another programming language like C you can not use that way, but you must manage the PChars yourself. Question: Why did you choose "Free Pascal" as language? Regards, Sven |
Re: Class with strings in DLL
I just googled this unit:
Code:
I didn't knew that FastMM4 unit can be used as replacement too, thanks for this tip :D
http://www.codexterity.com/fastsharemem.htm
I'm using D2010, FreePascal I selected by mistake, sorry :( I have next question, I used global (for DLL) record (it contains string and integers). When I used FastMM it detected memory leaks, when I nulled this record (rec.string := '', etc) memory leaks not occured. Why? |
AW: Re: Class with strings in DLL
Zitat:
Zitat:
Zitat:
Regards, Sven |
Re: Class with strings in DLL
So, it's global variable in DLL project file. Initialization id done by call specified function, function fills record with data. To null it I must call next function, because DLL entry procedure seems to not work.
Delphi-Quellcode:
procedure DLLIO(dwReason: DWORD);
begin case dwReason of DLL_PROCESS_ATTACH: {...}; DLL_PROCESS_DETACH: {...}; end; end; end; begin DllProc := @DLLIO; end. |
Re: Class with strings in DLL
I did it with external memory manager :)
But now I need use functions and classes with string parameters, I won't use memory manager, just PChar. How can I do it? |
AW: Class with strings in DLL
If you use PChar and so you don't need Sharemem.
Zitat:
Delphi-Quellcode:
If you have such source code you will get an AV because PChar is only a Pointer (of a special type). But after leaving this funktion "mystring" is freed and so "result" points to freed memory.
function GetString(): PChar;
var mystring: string; begin mystring := 'hello world'; result := myString; end; It would be interesting if you get the AV during the call or later when you use the result. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:14 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz