Forum > Beginners

Program flow

<< < (2/2)

RAW:
Or like this... (Thaddy's idea .... saw it somewhere else...)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure TForm1.FormClick(Sender: TObject);  Var   wnd: TForm; Begin  wnd:= TForm.Create(Self);   Try    wnd.Caption  := 'MyNewWindow';    wnd.SetBounds(300, 300, 300, 300);    wnd.OnPaint  := @MyNewWindowOnPaint;    wnd.ShowModal;   Finally    wnd.Release;    wnd:= Nil;   End; End;  {$J+}Procedure TForm1.MyNewWindowOnPaint(Sender: TObject);  Const   booOnce: Boolean = False; Begin  Inherited;   If Not booOnce  Then   Begin    ShowMessage('After creating my new modal window...');    booOnce:= True;   End; End;{$J-}

RAW:
In other words: the easiest thing is always to delete the AutoCreation line inside the LPR-file and create the window at your own position.

Open the LPR file: PROJECT, VIEW PROJECT SOURCE

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PROGRAM Project1;{$MODE OBJFPC}{$H+}{$J-}  USES  {$IFDEF UNIX}{$IFDEF UseCThreads}   cThreads,  {$ENDIF}{$ENDIF}   Interfaces,   Forms,   Unit1, unit2;   {$R *.RES} BEGIN RequireDerivedFormResource:= True;  Application.Initialize;  Application.CreateForm(TForm1, Form1);   // Delete this line Application.CreateForm(TForm2, Form2);   // No AutoCreation of the form !!!  Application.Run;END.
And then create the form at your own position...

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---UNIT Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Windows, Classes,  SysUtils,  Forms,   Controls, StdCtrls;  TYPE  TForm1 = Class(TForm)    Button1: TButton;    Procedure Button1Click (Sender: TObject);     PRIVATE     Procedure AsyncSound(Data: PtrInt);  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  USES Unit2; Procedure TForm1.Button1Click(Sender: TObject); Begin  Form2:= TForm2.Create(Self);  Form2.Show;   // After FormCreation do whatever you like !!!  Form2.StaticText1.Caption:= 'I am Form2...';  Form2.Button1.Caption    := 'I am the first button';  Form2.Edit1.Text         := 'Hello Hello Hello';   // Windows.Beep(800, 1000);  Application.QueueAsyncCall(@AsyncSound, 0); End;  Procedure TForm1.AsyncSound(Data: PtrInt); Begin  Windows.Beep(800, 1000); End; END.
This would be my first try in general...  :)

If the form isn't accessible, depending on what you want to do, then use a second thread...

mariodosreis:
 On Delphi i used the following code:
procedure TMainForm.OnMessageOwn(var Msg: TMsg; var Handled: Boolean) ;
var
  KeyState: TKeyboardState;
begin
 // Põe no ecram CpasLock NumLock etc...
  GetKeyboardState(KeyState);

  if KeyState[VK_NUMLOCK] = 0 then
    oStatusBar.Panels[5].Text:= '!'
  else
    oStatusBar.Panels[5].Text:= 'Num.';

  if KeyState[VK_CAPITAL] = 0 then
    oStatusBar.Panels[6].Text:= '!'
  else
    oStatusBar.Panels[6].Text:= 'Caps.';

  if KeyState[VK_INSERT] = 0 then
    oStatusBar.Panels[7].Text:= '!'
  else
    oStatusBar.Panels[7].Text:= 'Ins.';

end;
On Lazarus, since we don't have  Application.OnMessage := OnMessageOwn;
I' using the Application.OnIdle=IdleHandler like this:

procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
Var KeyState: Smallint;
begin
 // Delphi:    GetKeyboardState(KeyState);      // And $80
    if  GetKeyState(VK_SHIFT) <> 0 then
      StatusBar1.Panels[4].Text:= 'Shift'
    else
     StatusBar1.Panels[4].Text:= '?!'    ;

    if  GetKeyState(VK_NUMLOCK)) = 0 then
      StatusBar1.Panels[5].Text:= '?!'
    else
      StatusBar1.Panels[5].Text:= 'NºLock';

    if  GetKeyState(VK_CAPITAL)  = 0 then
      StatusBar1.Panels[6].Text:= '?!'
    else
      StatusBar1.Panels[6].Text:= 'Caps.';

    if  GetKeyState(VK_INSERT)  = 0 then
      StatusBar1.Panels[7].Text:= '?!'
    else
      StatusBar1.Panels[7].Text:= 'Ins.'

end;

The only inconvinient is the never ending loop while Idle!
Is there some other to achieve the same result?
Best regards

VTwin:
When you open a Form for editing, the "Object Inspector" "Events" pane has a list of events with help on what each is used for. These include OnCreate, OnShow, OnActivate, etc. Perhaps this is of help.

Thausand:
Can make use typed const: https://www.freepascal.org/docs-html/ref/refse10.html#x22-210002.2


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);Var KeyState: Smallint;const HaveKeyState:boolean=false;begin    if HaveKeyState then exit;  // Delphi:    GetKeyboardState(KeyState);      // And $80    if  GetKeyState(VK_SHIFT) <> 0 then      StatusBar1.Panels[4].Text:= 'Shift'    else     StatusBar1.Panels[4].Text:= '?!'    ;     if  GetKeyState(VK_NUMLOCK)) = 0 then      StatusBar1.Panels[5].Text:= '?!'    else      StatusBar1.Panels[5].Text:= 'NºLock';     if  GetKeyState(VK_CAPITAL)  = 0 then      StatusBar1.Panels[6].Text:= '?!'    else      StatusBar1.Panels[6].Text:= 'Caps.';     if  GetKeyState(VK_INSERT)  = 0 then      StatusBar1.Panels[7].Text:= '?!'    else      StatusBar1.Panels[7].Text:= 'Ins.'     HaveKeyState:=true;end; 

Navigation

[0] Message Index

[*] Previous page

Go to full version