Miletus. Send IntegerValue from one Form to another

How can i send a Variable startID:=10 to an new miletus form

i tried to declare a unit for both forms, but when i read integer in the newform its value is 0


It's not exactly clear what you are trying to achieve. Do you want to share a global variable between the two forms?

Yes thats what i want. I declare for example the integer var customerid with the value of 100 in the mainfom. when i show the 2nd miletus form i need the value of customerid to start a webserviec call.

I tried to use a unit to use with both forms but the value of the integer is 0 when i read it in the second form.

If you are using TMiletusWindow then this behavior is expected. You need to imagine the two forms/windows as two running instances of embedded browsers, they won't be able to share the client-side application, so they cannot share the global variable.

However, we have some messaging capabilities that you could use to send some data to the second form (documentation). This is a very simplified version but it should get the idea going. You can (and probably should) use a more structured message of course,this is just for demonstration purposes:

procedure TForm2.MiletusFormCreate(Sender: TObject);
  //Set up the connection to TMiletusWindow
  MiletusWindow1.FormClass := TForm1;
  //Sign up with an ID to the messaging:

procedure TForm2.MiletusFormFormMessage(Sender: TObject; FormID,
  AMessage: string);
  //If we receive a ready message from the child, it means it can communicate
  //Send the necessary data:
  if AMessage = 'ready' then
    SendMessage('childFormID', IntToStr(MyIntVariable));

procedure TForm1.MiletusFormCreate(Sender: TObject);
  //The form's OnCreate event is the first place we can say the form is ready for communication
  //Register with an ID then send a ready message to the main form:
  SendMessage('mainFormID', 'ready');

procedure TForm1.MiletusFormFormMessage(Sender: TObject; FormID,
  AMessage: string);
  //Here we handle any received messages (check for the sender FormID and parse the AMessage if necessary)
  WebLabel1.Caption := AMessage;

Thank you i 've seen the demo, but could not tranfer it to what i need. thx for the the code i think now i can manage this.

1 Like