Recent

Author Topic: [SOLVED] 2 active form  (Read 2723 times)

Scuba70

  • Newbie
  • Posts: 5
[SOLVED] 2 active form
« on: October 20, 2017, 07:08:20 pm »
Hi,

I want to use 2 forms.
1 form for input numbers.
1 form for the results.

every time when you input (new) numbers,
the second form have to calculate and show new result on second form.

Can someone show me a simple example?

Thanks in advance.

(sorry for my bad English)
« Last Edit: October 21, 2017, 07:15:29 pm by Scuba70 »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4467
  • I like bugs.
Re: 2 active form
« Reply #1 on: October 20, 2017, 08:13:29 pm »
What is the actual problem? What keeps you from implementing it yourself?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: 2 active form
« Reply #2 on: October 20, 2017, 08:24:39 pm »
If you are new to Lazarus / Pascal, then I suggest you look at some example code and projects.

Simple steps to get you going:

1. start a new project "Application"
2. add a second form.
3. get and process the data entered on form1 (that's unit1)
4. show the result on form2 (that's unit2)

See screenshot.
keep it simple

Handoko

  • Hero Member
  • *****
  • Posts: 5150
  • My goal: build my own game engine using Lazarus
Re: 2 active form
« Reply #3 on: October 20, 2017, 08:49:41 pm »
I wrote a small demo. You can download the FormTest.zip for testing.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, ComCtrls, StdCtrls, ExtCtrls, unit2;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Label1: TLabel;
  16.     LabeledEdit1: TLabeledEdit;
  17.     LabeledEdit2: TLabeledEdit;
  18.     RadioGroup1: TRadioGroup;
  19.     StatusBar1: TStatusBar;
  20.     procedure RadioGroup1Click(Sender: TObject);
  21.     procedure ValueChange(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.ValueChange(Sender: TObject);
  34. var
  35.   Val1      : Real;
  36.   Val2      : Real;
  37.   Total     : Real;
  38.   StrTotal  : string;
  39.   ErrorCode : Integer;
  40.   isError   : Boolean;
  41. begin
  42.  
  43.   // Calculate
  44.   Val(LabeledEdit1.Text, Val1, ErrorCode);
  45.   isError := (ErrorCode <> 0);
  46.   Val(LabeledEdit2.Text, Val2, ErrorCode);
  47.   isError := isError or (ErrorCode <> 0);
  48.   Total := Val1 + Val2;
  49.  
  50.   // Format
  51.   if isError
  52.   then StrTotal := ''
  53.   else StrTotal := FloatToStr(Total);
  54.  
  55.   // Show
  56.   StatusBar1.SimpleText := StrTotal;
  57.   Form2.Label1.Caption := StrTotal;
  58. end;
  59.  
  60. procedure TForm1.RadioGroup1Click(Sender: TObject);
  61. begin
  62.   case RadioGroup1.ItemIndex of
  63.     0: begin
  64.          StatusBar1.Visible := True;
  65.          Form2.Visible := False;
  66.        end;
  67.     1: begin
  68.          Form2.Visible := True;
  69.          Form2.Left := Form1.Left + Form1.Width + 10;
  70.          Form2.Top := Form1.Top;
  71.          StatusBar1.Visible := False;
  72.        end;
  73.   end;
  74. end;
  75.  
  76. end.
Note: the project was written using Lazarus 1.8.0RC5, older versions may have problem opening it.
« Last Edit: October 20, 2017, 08:53:39 pm by Handoko »

Scuba70

  • Newbie
  • Posts: 5
Re: 2 active form
« Reply #4 on: October 21, 2017, 10:40:41 am »
@Handoko, @Munair :

thanks for your explanation. It's easier than I thought  :D


 

TinyPortal © 2005-2018