Jump to content

Passing a global variable from a dynamic frame to MainForm


artem_niko

Recommended Posts

Good afternoon!

I will put my question in a separate topic, because I have almost solved it, but not completely, and I ask you to tell me why such an error occurs.

So, the task: to transfer from the dynamically created UniFrame1 to the main HModule program of the DLL package, which needs to be unloaded after closing the dynamically created UniTabSheet (parent for UniFrame1).

To date, this is what has been done.

In MainForm, I'm creating dynamically UniTabSheet1:

...
UniTabSheet1:=TUniTabSheet.Create(UniPageControl1);
UniTabSheet1.PageControl:=UniPageControl1;
UniTabSheet1.Parent:=UniPageControl1;
UniTabSheet1.Name:='UniTabSheet1_Test';
UniTabSheet1.Caption:='blabla';
UniTabSheet1.Visible:=True;
UniTabSheet1.Closable:=True;
UniTabSheet1.OnClose:=UniTabSheet_Close;
...

Also, after, I'm creating dynamically UniFrame1:

UniFrame1:=TUniFrame1.Create(self);
UniFrame1.Align:=alClient;
UniFrame1.Parent:=UniTabSheet1;
UniFrame1.Name:='TUniFrame1_Test';
if UniFrame1 <> nil then
begin
  //here, i'm transfer HModule of BPL from MainForm in my UniFrame1:
  if IsPublishedProp(UniFrame1,'GV_Test') then
  SetPropValue(UniFrame1,'GV_Test',MyHModuleValue);
end;

By the way, in MainForm I have it written like this:

...
private
    procedure SetGlobalValue_Test(const Value: HModule);
public
	TransferedBPL,GettingBPL: HMoudle;
published
    property GV_Test: HModule read TransferedBPL write SetGlobalValue_Test;
...

//getting HModule from UniFrame1 in MainForm:
procedure TMainForm.SetGlobalValue_Test(const Value: HMODULE);
begin
  GettingBPL:=Value;
end;

//unload BPL by getting HModule:
procedure TMainForm.UnloadAfterCloseUniTabSheet;
begin
  SetGlobalValue_Test(GettingBPL);
  UnloadPackage(GettingBPL);
end;

//when closing UniTabSheet1:
procedure TMainForm.UniTabSheet_Close(Sender: TObject; var AllowClose: Boolean);
begin
  UnloadAfterCloseUniTabSheet;
end;

In UniFrame 1, I get my HModule like this:

...
private
    procedure SetGlobalValue_Test2(const Value: HModule);
public
	TransferedBPL: HMoudle;
published
    property GV_Test2: HModule read TransferedBPL write SetGlobalValue_Test2;
...

procedure TUniFrame1.SetGlobalValue_Test2(const Value: HMODULE);
begin
  GV_Test2:=Value;
end;

In UniFrame1:

procedure TUniFrame1.UniLabel1Click(Sender: TObject);
begin
  if TransferedBPL <> 0 then
  begin
    if IsPublishedProp((Parent as TUniTabSheet),'GV_Test2') then
       SetPropValue((Parent as TUniTabSheet),'GV_Test2',TransferedBPL);
    end;
  end;
  (Parent as TUniTabSheet).Close;
end;

But, where I'm appling all this code, I'm getting error:

image.png.be2b4af143d8f4a2c15c716145185c83.png

Please, help me...

I found out for sure that all the code above works up to the point that my HModule is passed from MainForm to UniFrame1, I know for sure that it works.
I can't pass this HModule back to MainForm.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...