Jump to content

Use Forms without show them


cube18

Recommended Posts

Hi all,

is it possible to call methods (or read/set properties values) contained in a form, without showing the form itself?

For example: in my project there are 2 forms: Main and Unit1.

Unit Main:

//AllFeatures: Forms,Callback,icon-form-fieldui
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIRegClasses,  uniguiclasses, uniGUIForm, uniMemo, uniGUIBaseClasses, uniButton;

type
  TMainForm = class(TUniForm)
    UniMemo1: TUniMemo;
    btnTest1: TUniButton;
    bntTest2: TUniButton;
    procedure btnTest1Click(Sender: TObject);
    procedure bntTest2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowCallBack(Sender: TComponent; AResult:Integer);
  end;

function MainForm: TMainForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication, Unit1;

function MainForm: TMainForm;
begin
  Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;

procedure TMainForm.bntTest2Click(Sender: TObject);
begin
  //I'd like to call the function "UniForm1.Test" without UniForm1 shows
  UniMemo1.Lines.Add(UniForm1.Test);
end;

procedure TMainForm.btnTest1Click(Sender: TObject);
begin
  //I'd like to set the "UniForm1.pMessage" value without UniForm1 shows
  UniForm1.pMessage:='TEST!';
end;

initialization
  RegisterMainFormClass(TMainForm);

end.

Unit1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIForm, uniGUIBaseClasses, uniButton, uniLabel;

type
  TUniForm1 = class(TUniForm)
    UniButton1: TUniButton;
    UniButton2: TUniButton;
    UniLabel1: TUniLabel;
  private
    { Private declarations }
  public
    { Public declarations }
    pMessage: string;
    function Test: string;
  end;

function UniForm1: TUniForm1;

implementation

{$R *.dfm}

uses
  MainModule, uniGUIApplication;

function UniForm1: TUniForm1;
begin
  Result := TUniForm1(UniMainModule.GetFormInstance(TUniForm1));
end;

function TUniForm1.Test: string;
begin
  Result:='Hello world';
end;

end.

Is there any chance to execute btnTest1Click or btnTest2Click without the form Unit1 is displayed?

Thanks in advance.

 

Link to comment
Share on other sites

53 minutes ago, cube18 said:

Is there any chance to execute btnTest1Click or btnTest2Click without the form Unit1 is displayed?

Well, a form must be shown after it is create. Referring to UniForm1 instances automatically creates it which means that it should be shown.

You may need to use frames for such cases.

 

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...