• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

StringGrid inside a DLL

Hello.

I have one problem.

I try to use a stringgrid from inside a dll.

What I do is that I create it dynamicly in the main program.
Then in the dll I add some values into it.

But When I free the dll I get an Access Violation.

When I load the DLL I set the dll's application to the Programs Application. And I change it back before I unload it.

What can be the problem?
0
wqclatre
Asked:
wqclatre
  • 6
  • 4
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
maybe a reference to the StringList that is owned by the mainprogram...if you use a TStrings.assign(stringlistfromtheform) in the dll and then try to free it on dll.free, it give an AV as the assigned is owned by the form....
0
 
wqclatreAuthor Commented:
String List? Where in the string grid do I have this String List? Can you give me an example?

The StringGrid is owned by the Main program and is created on a form in the main program.
I just add values into StringGrid.Cells[ix,jx]:= 'SomeText';
from inside the dll.

When I do the same with a memmo instead I have no problem
0
 
wqclatreAuthor Commented:
SO what I do in the main program is something like this

frmTest := TFrmTest.Create(Application);
Sg:= TStringGrid.Create(frmTest);
SG.Parent:= frmTest;

Here I Load the dll and then add some values in the StringGrid.
Then I Unload the dll and free the frmTest. (And get the AccessViolation when I try to free the frmTest)


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
wqclatreAuthor Commented:
and about the dll:

First I do an Initialize. then I Work with the stringgrid and then I  deinitialize and unload it.
function Initialize(MyApp : TApplication) : Boolean;
begin
  if not Initialized then begin
    DLLApplication:=Application;
  end;
  Application:=QuoteApp;
  Initialized:=True;
  Result:=True;
end;

function Deinitialize : Boolean;
begin
  if Initialized then begin
    Application:=DLLApplication;
  end;
  Initialized:=False;
  Result:=True;
end;
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
OK Sorry for the typo...btw i was meaining this: how do you get access to the STringGrid? if you get a reference to it from the dll then freeing the dll frees also the referenced grid....so then freeing the form (that try to free the owned stringgrid too)  it raise the AV as the grid was already destroyed....
0
 
wqclatreAuthor Commented:
Should that be the problem when I Set the DLLApplication to the Main Program's Application?
0
 
wqclatreAuthor Commented:
And if so. Why does it work if I just switch to a memo instead?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
THe memo is also created on the fly or in design time?
0
 
wqclatreAuthor Commented:
Yes.

What I do is that I create the forms from an XML file.

So the code looks something like:

    if XMLChildNode.Attributes['type'] = 'TMemo' then
    begin
      memo:= TMemo.Create(ParentComponent);
      memo.Parent := ParentComponent;
      LoadXmlMemo(XMLChildNode,memo);
      memo.OnChange:= OnGlobalChange;
      memo.OnClick:= OnGlobalClick;
      memo.OnDblClick:= OnGlobalDblClick;
      memo.OnEnter:= OnGlobalEnter;
      memo.OnExit:= OnGlobalExit;
      memo.OnKeyDown:= OnGlobalKeyDown;
      memo.OnKeyPress:= OnGlobalKeyPress;
      memo.OnKeyUp:= OnGlobalKeyUp;
      CompList.AddObject(memo, XMLChildNode);
    end else
    if XMLChildNode.Attributes['type'] = 'TComboBox' then
    begin
      combo:= TCombobox.Create(ParentComponent);
      combo.Parent := ParentComponent;
      LoadXmlCombo(XMLChildNode,combo);
      combo.OnChange:= OnGlobalChange;
      combo.OnClick:= OnGlobalClick;
      combo.OnDblClick:= OnGlobalDblClick;
      combo.OnDropDown:= OnGlobalDropDown;
      combo.OnEnter:= OnGlobalEnter;
      combo.OnExit:= OnGlobalExit;
      combo.OnKeyDown:= OnGlobalKeyDown;
      combo.OnKeyPress:= OnGlobalKeyPress;
      combo.OnKeyUp:= OnGlobalKeyUp;
      CompList.AddObject(combo, XMLChildNode);
    end else
    if XMLChildNode.Attributes['type'] = 'TGroupBox' then
    begin
      gb:= TGroupBox.Create(ParentComponent);
      gb.Parent := ParentComponent;
      LoadXmlGB(XMLChildNode,gb);
      CompList.AddObject(gb, XMLChildNode);
      if XMLChildNode.HasChildNodes then
        ParseXMLChildNodes(XMLChildNode, gb);
    end else
    if XMLChildNode.Attributes['type'] = 'TStringGrid' then
    begin
      sg:= TStringGrid.Create(ParentComponent);
      sg.Parent := ParentComponent;
      sg.OnSelectCell:= OnGlobalSelectCell;
      LoadXmlSG(XMLChildNode,sg);
      CompList.AddObject(sg, XMLChildNode);
      if XMLChildNode.HasChildNodes then
        ParseXMLChildNodes(XMLChildNode, sg);
    end;


The strange thing is that If i free the StringGrid inside the dll I have no problem.
(But it's created in the MainProgram and I just fill in values in the dll. then try to free it in the main program again) I do the same with the other components abowe but only string grid gives me the problem
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
That depends on some TSTringGrid pointers that are assigned to objects cells and allocated during the creation...
In the STringGrid destroy it frees the referenced object, but these pointers don't become nil anymore...
So destroying the STrigGrid from the Dll doesn't deallocate the pointers that are still resolved by the app, but the referenced object were destroyed so trying to destroy them raises the AV....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now