AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Class with strings in DLL

Ein Thema von WojTec · begonnen am 1. Jan 2011 · letzter Beitrag vom 7. Jan 2011
Antwort Antwort
Seite 1 von 2  1 2      
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Class with strings in DLL

  Alt 1. Jan 2011, 18:50
Delphi-Version: 2010
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

Geändert von WojTec ( 2. Jan 2011 um 15:21 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Class with strings in DLL

  Alt 1. Jan 2011, 20:13
U have to use the Unit sharemem (in DLL and Application)
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#3

AW: Class with strings in DLL

  Alt 1. Jan 2011, 21:18
To share string is needed Delphi-Referenz durchsuchenShareMem.

Classes may not be shared, because using the EXE and DLL separate RTTIs.
> runtime packages
$2B or not $2B
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#4

Re: Class with strings in DLL

  Alt 2. Jan 2011, 11:30
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)?
  Mit Zitat antworten Zitat
Benutzerbild von JamesTKirk
JamesTKirk

Registriert seit: 9. Sep 2004
Ort: München
604 Beiträge
 
FreePascal / Lazarus
 
#5

AW: Class with strings in DLL

  Alt 2. Jan 2011, 12:24
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
Sven
[Free Pascal Compiler Entwickler]
this post is printed on 100% recycled electrons
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#6

Re: Class with strings in DLL

  Alt 2. Jan 2011, 12:55
I just googled this unit:

Code:
http://www.codexterity.com/fastsharemem.htm
I didn't knew that FastMM4 unit can be used as replacement too, thanks for this tip

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?
  Mit Zitat antworten Zitat
Benutzerbild von JamesTKirk
JamesTKirk

Registriert seit: 9. Sep 2004
Ort: München
604 Beiträge
 
FreePascal / Lazarus
 
#7

AW: Re: Class with strings in DLL

  Alt 2. Jan 2011, 13:18
I just googled this unit:

Code:
http://www.codexterity.com/fastsharemem.htm
I didn't knew that FastMM4 unit can be used as replacement too, thanks for this tip
I believe that FastMM4 is better than fastsharemem, especially as it allows you to detect memory leaks.

Zitat von WojTec:
I'm using D2010, FreePascal I selected by mistake, sorry
Nobody is perfect. I was just curious.

Zitat von WojTec:
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?
When do you initialize that record? It could be a false alarm, but I'm not that fond with FastMM as I'm not using it as leak detector.

Regards,
Sven
Sven
[Free Pascal Compiler Entwickler]
this post is printed on 100% recycled electrons
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#8

Re: Class with strings in DLL

  Alt 2. Jan 2011, 15:02
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.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#9

Re: Class with strings in DLL

  Alt 7. Jan 2011, 17:58
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?
  Mit Zitat antworten Zitat
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#10

AW: Class with strings in DLL

  Alt 7. Jan 2011, 18:08
If you use PChar and so you don't need Sharemem.
Zitat:
When I try use any function from it, raises AV
Do you have this Problem only if you have strings in your dll? I suppose you have source like this:
Delphi-Quellcode:
function GetString(): PChar;
var
  mystring: string;
begin
  mystring := 'hello world';
  result := myString;
end;
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.

It would be interesting if you get the AV during the call or later when you use the result.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:39 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz